Skip to content

Commit

Permalink
Enhacements (#13)
Browse files Browse the repository at this point in the history
* Update infection, actions and remove set-env deprecated.
* Use roave/infection-static-analysis-plugin.
* Update action use roave-infection-static-analysis-plugin.
* Update version php.
* Fix minor corrections.
* Fix static analysis.
  • Loading branch information
terabytesoftw committed Nov 4, 2020
1 parent 0b47468 commit a3ad2f7
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 65 deletions.
22 changes: 2 additions & 20 deletions .github/workflows/build.yml
Expand Up @@ -9,9 +9,7 @@ jobs:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

env:
extensions: mbstring
key: cache-v1
update: true

runs-on: ${{ matrix.os }}

Expand All @@ -29,37 +27,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2

- name: Determine composer cache directory on Linux
if: matrix.os == 'ubuntu-latest'
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Determine composer cache directory on Windows
if: matrix.os == 'windows-latest'
run: ECHO "::set-env name=COMPOSER_CACHE_DIR::~\AppData\Local\Composer"
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer
uses: actions/cache@v2
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/mutation.yml
Expand Up @@ -10,9 +10,6 @@ jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

env:
update: true

runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -36,7 +33,7 @@ jobs:
tools: composer:v2

- name: Determine composer cache directory
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
Expand All @@ -49,10 +46,9 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run test mutation infection with coverage
- name: Run infection
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml --colors=always
vendor/bin/infection --threads=2 --coverage=build/logs --show-mutations --no-progress --skip-initial-tests --min-msi=95 --min-covered-msi=95
git fetch --depth=1 origin $GITHUB_BASE_REF
vendor/bin/roave-infection-static-analysis-plugin -j2 --git-diff-filter=A --git-diff-base=origin/$GITHUB_BASE_REF --logger-github --ignore-msi-with-no-mutations --only-covered
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
coverage: none

- name: Determine composer cache directory
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
@@ -1,6 +1,6 @@
build:
environment:
php: "7.4"
php: "7.4.12"
nodes:
analysis:
tests:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -30,9 +30,9 @@
"yiisoft/widget": "@dev"
},
"require-dev": {
"infection/infection": "^0.19",
"phpunit/phpunit": "^9.4",
"vimeo/psalm": "^4.0",
"roave/infection-static-analysis-plugin": "^1.3",
"vimeo/psalm": "^4.1",
"yiisoft/di": "^3.0@dev"
},
"autoload": {
Expand Down
53 changes: 24 additions & 29 deletions src/Menu.php
Expand Up @@ -4,7 +4,6 @@

namespace Yiisoft\Yii\Bulma;

use Closure;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;

Expand Down Expand Up @@ -387,38 +386,34 @@ private function normalizeItems(array $items, ?bool &$active): array
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
continue;
}

if (!isset($item['label'])) {
$item['label'] = '';
}

$encodeLabel = $item['encode'] ?? $this->encodeLabels;
$items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$hasActiveChild = false;

if (isset($item['items'])) {
$items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild);
if (empty($items[$i]['items']) && $this->hideEmptyItems) {
unset($items[$i]['items']);
if (!isset($item['url'])) {
unset($items[$i]);
continue;
} else {
$item['label'] = $item['label'] ?? '';
$encodeLabel = $item['encode'] ?? $this->encodeLabels;
$items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$hasActiveChild = false;

if (isset($item['items'])) {
$items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild);
if (empty($items[$i]['items']) && $this->hideEmptyItems) {
unset($items[$i]['items']);
if (!isset($item['url'])) {
unset($items[$i]);
continue;
}
}
}
}

if (!isset($item['active'])) {
if (($this->activateParents && $hasActiveChild) || ($this->activateItems && $this->isItemActive($item))) {
$active = $items[$i]['active'] = true;
} else {
$items[$i]['active'] = false;
if (!isset($item['active'])) {
if (($this->activateParents && $hasActiveChild) || ($this->activateItems && $this->isItemActive($item))) {
$active = $items[$i]['active'] = true;
} else {
$items[$i]['active'] = false;
}
} elseif (is_callable($item['active'])) {
$active = $items[$i]['active'] = call_user_func($item['active'], $item, $hasActiveChild, $this->isItemActive($item), $this);
} elseif ($item['active']) {
$active = $item['active'];
}
} elseif ($item['active'] instanceof Closure) {
$active = $items[$i]['active'] = call_user_func($item['active'], $item, $hasActiveChild, $this->isItemActive($item), $this);
} elseif ($item['active']) {
$active = true;
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/Nav.php
Expand Up @@ -224,11 +224,9 @@ private function renderItems(): string
$items = [];

foreach ($this->items as $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
if (!isset($item['visible']) || $item['visible']) {
$items[] = $this->renderItem($item);
}

$items[] = $this->renderItem($item);
}

return implode("\n", $items);
Expand Down
5 changes: 5 additions & 0 deletions src/NavBar.php
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Yii\Bulma;

use JsonException;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;

Expand Down Expand Up @@ -289,6 +290,8 @@ private function renderBrand(): void
/**
* Renders collapsible toggle button.
*
* @throws JsonException
*
* @return string the rendering toggle button.
*/
private function renderToggleButton(): string
Expand All @@ -303,6 +306,8 @@ private function renderToggleButton(): string
/**
* Render icon toggle.
*
* @throws JsonException
*
* @return string
*/
private function renderToggleIcon(): string
Expand Down

0 comments on commit a3ad2f7

Please sign in to comment.