From 71368863c5f81822e895f6efaae4fb44d3bf0a5a Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Thu, 16 Dec 2021 09:33:54 +0000 Subject: [PATCH 1/2] Add strict_types everywhere --- CHANGELOG.md | 4 +++ examples/ascii-art.php | 1 + examples/basic-centered.php | 1 + examples/basic-separation.php | 1 + examples/basic.php | 1 + examples/borders.php | 1 + examples/checkbox-item.php | 1 + examples/confirm-cancellable.php | 1 + examples/confirm.php | 1 + examples/crazy-redraw.php | 1 + examples/crazy-separation.php | 1 + examples/custom-item-register.php | 1 + examples/custom-mapping.php | 1 + examples/custom-styles.php | 1 + examples/disabled-items.php | 1 + examples/draw.php | 1 + examples/flash.php | 1 + examples/input-advanced.php | 1 + examples/input-custom.php | 1 + examples/input-number.php | 1 + examples/input-password.php | 1 + examples/input-text.php | 1 + examples/item-extra-toggling.php | 1 + examples/item-extra.php | 1 + examples/nested-submenu.php | 1 + examples/radio-item.php | 1 + examples/redraw.php | 1 + examples/remove-defaults.php | 1 + examples/shortcuts.php | 1 + examples/split-checkbox-item.php | 1 + examples/split-item.php | 1 + examples/split-radio-item.php | 1 + examples/submenu.php | 1 + examples/useful-separation.php | 1 + src/Action/ExitAction.php | 1 + src/Action/GoBackAction.php | 1 + src/Builder/CliMenuBuilder.php | 1 + src/Builder/SplitItemBuilder.php | 1 + src/CliMenu.php | 1 + src/Dialogue/CancellableConfirm.php | 1 + src/Dialogue/Confirm.php | 1 + src/Dialogue/Dialogue.php | 1 + src/Dialogue/Flash.php | 1 + src/Exception/InvalidShortcutException.php | 1 + src/Exception/InvalidTerminalException.php | 1 + src/Exception/MenuNotOpenException.php | 1 + src/Frame.php | 1 + src/Input/Input.php | 1 + src/Input/InputIO.php | 1 + src/Input/InputResult.php | 1 + src/Input/Number.php | 5 ++-- src/Input/Password.php | 1 + src/Input/Text.php | 1 + src/MenuItem/AsciiArtItem.php | 1 + src/MenuItem/CheckboxItem.php | 1 + src/MenuItem/LineBreakItem.php | 1 + src/MenuItem/MenuItemInterface.php | 1 + src/MenuItem/MenuMenuItem.php | 1 + src/MenuItem/RadioItem.php | 1 + src/MenuItem/SelectableItem.php | 1 + src/MenuItem/SplitItem.php | 1 + src/MenuItem/StaticItem.php | 1 + src/MenuStyle.php | 1 + src/Style/CheckboxStyle.php | 1 + src/Style/RadioStyle.php | 1 + src/Style/SelectableStyle.php | 1 + src/Terminal/TerminalFactory.php | 1 + src/Util/ColourUtil.php | 1 + src/Util/StringUtil.php | 1 + test/Action/ExitActionTest.php | 1 + test/Action/GoBackActionTest.php | 1 + test/Builder/CliMenuBuilderTest.php | 13 +++++----- test/Builder/SplitItemBuilderTest.php | 1 + test/CliMenuTest.php | 1 + test/Dialogue/ConfirmTest.php | 1 + test/Dialogue/FlashTest.php | 1 + .../InvalidTerminalExceptionTest.php | 1 + test/Exception/MenuNotOpenExceptionTest.php | 1 + test/FrameTest.php | 1 + test/Input/InputIOTest.php | 4 ++- test/Input/InputResultTest.php | 1 + test/Input/NumberTest.php | 1 + test/Input/PasswordTest.php | 1 + test/Input/TextTest.php | 1 + test/MenuItem/AsciiArtItemTest.php | 1 + test/MenuItem/CheckboxItemTest.php | 1 + test/MenuItem/LineBreakItemTest.php | 1 + test/MenuItem/MenuMenuItemTest.php | 1 + test/MenuItem/RadioItemTest.php | 1 + test/MenuItem/SelectableItemTest.php | 1 + test/MenuItem/SplitItemTest.php | 1 + test/MenuItem/StaticItemTest.php | 1 + test/MenuStyleTest.php | 15 +++++------ test/Util/ColourUtilTest.php | 25 ++++++++++--------- test/Util/StringUtilTest.php | 1 + 95 files changed, 127 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5331681f..d240359e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ### Removed +## [4.2.1] +### Fixed +- PHP 8.1 Support (#252, #249) + ## [4.2.0] ### Added - Yes/no comfirmation dialogue (#248) diff --git a/examples/ascii-art.php b/examples/ascii-art.php index 0273d2d2..c43589d3 100644 --- a/examples/ascii-art.php +++ b/examples/ascii-art.php @@ -1,4 +1,5 @@ inputIO->registerControlCallback(InputCharacter::UP, function (string $input) { - return $this->validate($input) ? (int) $input + 1 : $input; + return $this->validate($input) ? (string) ((int) $input + 1) : $input; }); $this->inputIO->registerControlCallback(InputCharacter::DOWN, function (string $input) { - return $this->validate($input) ? (int) $input - 1 : $input; + return $this->validate($input) ? (string) ((int) $input - 1) : $input; }); return $this->inputIO->collect($this); diff --git a/src/Input/Password.php b/src/Input/Password.php index 1c25d16d..0748c541 100644 --- a/src/Input/Password.php +++ b/src/Input/Password.php @@ -1,4 +1,5 @@ willReturn(256); $builder = new CliMenuBuilder($terminal); - $builder->setBackgroundColour(16, 'white'); - $builder->setForegroundColour(206, 'red'); + $builder->setBackgroundColour('16', 'white'); + $builder->setForegroundColour('206', 'red'); $style = $builder->build() ->getStyle(); @@ -260,8 +261,8 @@ public function test256ColoursCodes() : void ->willReturn(8); $builder = new CliMenuBuilder($terminal); - $builder->setBackgroundColour(16, 'white'); - $builder->setForegroundColour(206, 'red'); + $builder->setBackgroundColour('16', 'white'); + $builder->setForegroundColour('206', 'red'); $style = $builder->build() ->getStyle(); @@ -283,7 +284,7 @@ public function testSetFgThrowsExceptionWhenColourCodeIsNotInRange() : void ->willReturn(256); $builder = new CliMenuBuilder($terminal); - $builder->setForegroundColour(512, 'white'); + $builder->setForegroundColour('512', 'white'); } public function testSetBgThrowsExceptionWhenColourCodeIsNotInRange() : void @@ -300,7 +301,7 @@ public function testSetBgThrowsExceptionWhenColourCodeIsNotInRange() : void ->willReturn(256); $builder = new CliMenuBuilder($terminal); - $builder->setBackgroundColour(257, 'white'); + $builder->setBackgroundColour('257', 'white'); } public function testDisableDefaultItems() : void diff --git a/test/Builder/SplitItemBuilderTest.php b/test/Builder/SplitItemBuilderTest.php index 9601b484..971f633a 100644 --- a/test/Builder/SplitItemBuilderTest.php +++ b/test/Builder/SplitItemBuilderTest.php @@ -1,4 +1,5 @@ inputIO->registerControlCallback(InputCharacter::UP, function ($input) { - return ++$input; + $input = (int) $input; + return (string ) ++$input; }); $this->terminal diff --git a/test/Input/InputResultTest.php b/test/Input/InputResultTest.php index 5838421d..a93dc46d 100644 --- a/test/Input/InputResultTest.php +++ b/test/Input/InputResultTest.php @@ -1,4 +1,5 @@ getMockBuilder(UnixTerminal::class) ->disableOriginalConstructor() - ->setMethods(['getWidth', 'getColourSupport']) + ->onlyMethods(['getWidth', 'getColourSupport']) ->getMock(); $terminal @@ -194,15 +195,15 @@ public function testSetBorderShorthandFunction() : void public function test256ColoursCodes() : void { $style = $this->getMenuStyle(256); - $style->setBg(16, 'white'); - $style->setFg(206, 'red'); + $style->setBg('16', 'white'); + $style->setFg('206', 'red'); static::assertSame('16', $style->getBg()); static::assertSame('206', $style->getFg()); static::assertSame("\033[38;5;206;48;5;16m", $style->getColoursSetCode()); $style = $this->getMenuStyle(8); - $style->setBg(16, 'white'); - $style->setFg(206, 'red'); + $style->setBg('16', 'white'); + $style->setFg('206', 'red'); static::assertSame('white', $style->getBg()); static::assertSame('red', $style->getFg()); static::assertSame("\033[31;47m", $style->getColoursSetCode()); @@ -214,7 +215,7 @@ public function testSetFgThrowsExceptionWhenColourCodeIsNotInRange() : void $this->expectExceptionMessage('Invalid colour code'); $style = $this->getMenuStyle(256); - $style->setFg(512, 'white'); + $style->setFg('512', 'white'); } public function testSetBgThrowsExceptionWhenColourCodeIsNotInRange() : void @@ -223,7 +224,7 @@ public function testSetBgThrowsExceptionWhenColourCodeIsNotInRange() : void $this->expectExceptionMessage('Invalid colour code'); $style = $this->getMenuStyle(256); - $style->setBg(257, 'white'); + $style->setBg('257', 'white'); } public function testWidthCalculation() : void diff --git a/test/Util/ColourUtilTest.php b/test/Util/ColourUtilTest.php index 74511c04..85e52e0f 100644 --- a/test/Util/ColourUtilTest.php +++ b/test/Util/ColourUtilTest.php @@ -1,4 +1,5 @@ method('getColourSupport') ->willReturn(8); - ColourUtil::validateColour($terminal, 255, 'teal'); + ColourUtil::validateColour($terminal, '255', 'teal'); } public function testValidateColourWithFallbackWhenTerminalDoesNotSupport256Colours() : void @@ -74,7 +75,7 @@ public function testValidateColourWithFallbackWhenTerminalDoesNotSupport256Colou ->method('getColourSupport') ->willReturn(8); - self::assertEquals('red', ColourUtil::validateColour($terminal, 255, 'red')); + self::assertEquals('red', ColourUtil::validateColour($terminal, '255', 'red')); } public function testValidateColourPicksFallbackFromPreComputedListWhenTerminalDoesNotSupport256Colours() : void @@ -84,13 +85,13 @@ public function testValidateColourPicksFallbackFromPreComputedListWhenTerminalDo ->method('getColourSupport') ->willReturn(8); - self::assertEquals('yellow', ColourUtil::validateColour($terminal, 148)); + self::assertEquals('yellow', ColourUtil::validateColour($terminal, '148')); } /** * @dataProvider invalidColourCodeProvider */ - public function testValidateColourThrowsExceptionIfInvalid256ColourCodeUsed(int $colourCode) : void + public function testValidateColourThrowsExceptionIfInvalid256ColourCodeUsed(string $colourCode) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -100,16 +101,16 @@ public function testValidateColourThrowsExceptionIfInvalid256ColourCodeUsed(int public function invalidColourCodeProvider() : array { return [ - [-1], - [256], - [1000], + ['-1'], + ['256'], + ['1000'], ]; } /** * @dataProvider validColourCodeProvider */ - public function testValidateColourWith256ColoursWhenTerminalSupports256Colours(int $colourCode) : void + public function testValidateColourWith256ColoursWhenTerminalSupports256Colours(string $colourCode) : void { $terminal = $this->createMock(Terminal::class); $terminal->expects($this->once()) @@ -122,10 +123,10 @@ public function testValidateColourWith256ColoursWhenTerminalSupports256Colours(i public function validColourCodeProvider() : array { return [ - [0], - [255], - [1], - [100], + ['0'], + ['255'], + ['1'], + ['100'], ]; } diff --git a/test/Util/StringUtilTest.php b/test/Util/StringUtilTest.php index 24b0242c..e52c3605 100644 --- a/test/Util/StringUtilTest.php +++ b/test/Util/StringUtilTest.php @@ -1,4 +1,5 @@ Date: Thu, 16 Dec 2021 09:38:07 +0000 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d240359e..842b4838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,16 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ### Removed -## [4.2.1] +## [4.3.0] ### Fixed -- PHP 8.1 Support (#252, #249) + - PHP 8.1 Support (#252, #249) + +### Added + - declare(strict_types=1) everywhere ## [4.2.0] ### Added - - Yes/no comfirmation dialogue (#248) + - Yes/no confirmation dialogue (#248) - Ability to add multiple checkbox and radio items (#241) ## [4.1.0]