diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..55c512b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + tests: + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + php: ['8.2', '8.3', '8.4', '8.5'] + name: PHP ${{ matrix.php }} + env: + TERM: xterm-256color + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - uses: ramsey/composer-install@v3 + with: + dependency-versions: highest + - run: vendor/bin/phpunit --stop-on-error + - if: matrix.php == '8.5' + run: composer cs-dry-run + - if: matrix.php == '8.5' + run: composer static diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml deleted file mode 100644 index 7e44aa7..0000000 --- a/.github/workflows/static.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Static Analysis - -on: ['push', 'pull_request'] - -jobs: - ci: - runs-on: ubuntu-latest - strategy: - matrix: - php: ['8.4'] - name: Code Style - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - tools: composer:v2 - ini-values: pcov.directory=api #optional, see above for usage. - coverage: pcov - - - name: Install Dependencies - run: composer update --no-interaction --no-progress - - - name: Run cs fixer - run: composer run cs-dry-run - - - name: Run PHPStan - run: composer run static diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index d091432..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Tests - -on: ['push', 'pull_request'] - -jobs: - ci: - runs-on: ubuntu-latest - strategy: - matrix: - php: ['8.2', '8.3', '8.4'] - - name: PHP ${{ matrix.php }} - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - tools: composer:v2 - coverage: xdebug - - - name: Setup Problem Matches - run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Install cdependencies - run: composer update --no-interaction --no-progress - - - name: Tests - run: TERM=xterm-256color ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml - - - uses: codecov/codecov-action@v1 diff --git a/README.md b/README.md index adcc49c..288a337 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,7 @@
-
-
-
-
-
-
-
-
-
-
+
diff --git a/composer.json b/composer.json
index 03ae403..bc5d9a8 100644
--- a/composer.json
+++ b/composer.json
@@ -21,7 +21,7 @@
"require": {
"php" : ">=8.2",
"beberlei/assert": "^2.4 | ^3",
- "php-school/terminal": "^0.2.1",
+ "php-school/terminal": "^0.3",
"ext-posix": "*",
"ext-mbstring": "*"
},
diff --git a/src/CliMenu.php b/src/CliMenu.php
index 87a9603..cbf9868 100644
--- a/src/CliMenu.php
+++ b/src/CliMenu.php
@@ -345,17 +345,26 @@ protected function moveSelectionVertically(string $direction): void
} while (!$this->canSelect());
}
+ private function getSelectedMenuItem(): MenuItemInterface
+ {
+ if (null === $this->selectedItem) {
+ throw new \RuntimeException('No item is currently selected');
+ }
+
+ return $this->items[$this->selectedItem];
+ }
+
/**
* Move the selection in a given direction, left / right
*/
protected function moveSelectionHorizontally(string $direction): void
{
- if (!$this->items[$this->selectedItem] instanceof SplitItem) {
+ if (!$this->getSelectedMenuItem() instanceof SplitItem) {
return;
}
/** @var SplitItem $item */
- $item = $this->items[$this->selectedItem];
+ $item = $this->getSelectedMenuItem();
$itemKeys = array_keys($item->getItems());
$selectedItemIndex = $item->getSelectedItemIndex();
@@ -391,7 +400,7 @@ protected function moveSelectionHorizontally(string $direction): void
*/
private function canSelect(): bool
{
- return $this->items[$this->selectedItem]->canSelect();
+ return $this->getSelectedMenuItem()->canSelect();
}
/**
@@ -404,7 +413,7 @@ public function getSelectedItem(): MenuItemInterface
throw new \RuntimeException('No selected item');
}
- $item = $this->items[$this->selectedItem];
+ $item = $this->getSelectedMenuItem();
return $item instanceof SplitItem
? $item->getSelectedItem()
: $item;
@@ -441,7 +450,7 @@ public function getItemByIndex(int $index): MenuItemInterface
public function executeAsSelected(MenuItemInterface $item): void
{
- $current = $this->items[$this->selectedItem];
+ $current = $this->getSelectedMenuItem();
$this->setSelectedItem($item);
$this->executeCurrentItem();
$this->setSelectedItem($current);
diff --git a/test/MenuStyleTest.php b/test/MenuStyleTest.php
index e841443..667edbd 100644
--- a/test/MenuStyleTest.php
+++ b/test/MenuStyleTest.php
@@ -51,7 +51,6 @@ public function testMenuStyleCanBeInstantiatedByCliMenuBuilder(): void
self::assertTrue($reflectionMenu->hasProperty('style'));
$styleProperty = $reflectionMenu->getProperty('style');
- $styleProperty->setAccessible(true);
$style = $styleProperty->getValue($menu);
self::assertSame(MenuStyle::class, get_class($style));
@@ -678,7 +677,6 @@ public function testDebugMode(): void
$style = $this->getMenuStyle(8, 40);
$prop = new \ReflectionProperty(MenuStyle::class, 'debugMode');
- $prop->setAccessible(true);
$prop->setValue($style, true);
$style->setWidth(30);