Skip to content

Commit

Permalink
Merge pull request #4 from eclipxe13/maintenance-20220715
Browse files Browse the repository at this point in the history
Maintenance 2022-06-15 (version 0.1.3)
  • Loading branch information
eclipxe13 authored Jul 18, 2022
2 parents 22d33f5 + 41b3647 commit a2e101b
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 69 deletions.
62 changes: 23 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
name: build
on:
pull_request:
branches: [ main ]
branches: [ "main" ]
push:
branches: [ main ]
branches: [ "main" ]
schedule:
- cron: '0 16 * * 0' # sunday 16:00

# Actions:
# shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action

jobs:
phpcs:
name: Coding standards (phpcs)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2, cs2pr, phpcs
tools: cs2pr, phpcs
env:
fail-fast: true

- name: Coding standards (phpcs)
run: phpcs -q --report=checkstyle | cs2pr

Expand All @@ -31,16 +33,15 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2, cs2pr, php-cs-fixer
tools: cs2pr, php-cs-fixer
env:
fail-fast: true

- name: Coding standards (php-cs-fixer)
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr

Expand All @@ -52,30 +53,26 @@ jobs:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
tools: composer:v2
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist

- name: Tests (phpunit)
run: vendor/bin/phpunit --testdox --verbose

Expand All @@ -84,30 +81,26 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2, phpstan
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist

- name: Static analysis (phpstan)
run: phpstan analyse --no-progress --verbose

Expand All @@ -116,30 +109,26 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2, psalm
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist

- name: Static analysis (psalm)
run: psalm --no-progress

Expand All @@ -148,31 +137,26 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2

uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: '7.4' # cannot use a greater php version because of phpunit version compatibility
coverage: xdebug
tools: composer:v2
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist

- name: Mutation testing (infection)
# run this way because infection phar is not working on php 7.4
run: |
Expand Down
12 changes: 6 additions & 6 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.8.0" installed="3.8.0" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.6.2" installed="3.6.2" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.6.2" installed="3.6.2" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^1.6.9" installed="1.6.9" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="^4.23.0" installed="4.23.0" location="./tools/psalm" copy="false"/>
<phar name="infection" version="^0.26.6" installed="0.26.6" location="./tools/infection" copy="false"/>
<phar name="php-cs-fixer" version="^3.9.4" installed="3.9.4" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.7.1" installed="3.7.1" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.7.1" installed="3.7.1" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^1.8.1" installed="1.8.1" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="^4.24.0" installed="4.24.0" location="./tools/psalm" copy="false"/>
<phar name="infection" version="^0.26.13" installed="0.26.13" location="./tools/infection" copy="false"/>
</phive>
5 changes: 4 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ build:
- composer upgrade --no-interaction --prefer-dist
nodes:
analysis: # see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/
environment:
php:
version: 7.4
project_setup: { override: true }
tests:
override:
- php-scrutinizer-run --enable-security-analysis
- command: vendor/bin/phpunit --verbose --testdox --coverage-clover=coverage.clover
- command: php -dzend_extension=xdebug.so -dxdebug.mode=coverage vendor/bin/phpunit --verbose --testdox --coverage-clover=coverage.clover
coverage:
file: coverage.clover
format: clover
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ as they must only exist inside this project. Do not use them in your project.
## Contributing

Contributions are welcome! Please read [CONTRIBUTING][] for details
and don't forget to take a look in the [TODO][] and [CHANGELOG][] files.
and don't forget to take a look in [TODO][] and [CHANGELOG][] files.

## Copyright and License

Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"Eclipxe\\MicroCatalog\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"infection/extension-installer": false
}
},
"scripts": {
"dev:build": ["@dev:fix-style", "@dev:test"],
"dev:check-style": [
Expand Down
22 changes: 16 additions & 6 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ In summary, [SemVer](https://semver.org/) can be viewed as `[ Breaking ].[ Featu

**Version `0.x.x` doesn't have to apply any of the SemVer rules**

## Unreleased 2022-05-23
## Version 0.1.3 2022-07-18

Add type template to `MicroCatalog<TEntry>`.

Fix GitHub workflow by configure `infection/extension-installer` plugin.

Fix Scrutinizer CI running on PHP 7.4 to allow code coverage creation.

This release includes also the following previously unreleased changes.

### Unreleased 2022-05-23

Project Maintenance:

Expand All @@ -19,11 +29,11 @@ Project Maintenance:
- Update license year.
- Update code style standard to PSR 12 and configuration files.

## Unreleased 2021-11-20
### Unreleased 2021-11-20

Fixed CI. New phpstan version complains about weak return types on example test classes.

## Unreleased 2021-09-25
### Unreleased 2021-09-25

Fixed CI. Infection fails because it is not working on PHP 7.4.
PHPUnit cannot create code coverage for infection on PHP 8.0; so, upgrade to PHP 8.0 is not a solution.
Expand All @@ -33,18 +43,18 @@ Remove unused extensions on GitHub Actions.

Move code coverage generation to Scrutinizer.

## Unreleased 2021-06-18
### Unreleased 2021-06-18

Fix description on `composer dev:build`.

PHPUnit should not be verbose by default.

## Unreleased 2021-06-17
### Unreleased 2021-06-17

Migrate from Travis-CI to GitHub Actions. Thanks Travis-CI!
Code coverage is build on GitHub and uploaded to Scrutinizer.

## Unreleased 2021-06-13
### Unreleased 2021-06-13

Maintenance on development environment, didn't change any source inside `src/`.

Expand Down
33 changes: 21 additions & 12 deletions src/MicroCatalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@
use Eclipxe\MicroCatalog\Exceptions\BadMethodCallException;
use Eclipxe\MicroCatalog\Exceptions\IndexTypeError;

/**
* @template TEntry
*/
abstract class MicroCatalog
{
/** @var string|int */
private $index;

/** @var mixed */
/** @var TEntry */
private $value;

/**
* MicroCatalog constructor.
*
* @param string|int|mixed $index
* @param string|int $index
*/
public function __construct($index)
{
/**
* @psalm-suppress DocblockTypeContradiction
* @phpstan-ignore-next-line
*/
if (! is_string($index) && ! is_int($index)) {
throw new IndexTypeError(static::class, $index);
}
Expand All @@ -30,17 +37,17 @@ public function __construct($index)
}

/**
* Override this function to setup the predefined values
* Override this function to set up the predefined values
*
* @return array<mixed>
* @return array<TEntry>
*/
abstract public static function getEntriesArray(): array;

/**
* Override this function to set a default value if the index is not found
* You can even throw an exception to not allow an element without definition
*
* @return mixed
* @return TEntry
*/
abstract public function getEntryValueOnUndefined();

Expand Down Expand Up @@ -80,26 +87,28 @@ public function getEntryId(): string
return strval($this->index);
}

/** @return mixed */
/** @return TEntry */
public function getEntryValue()
{
return $this->value;
}

/**
* @param string $key
* @return mixed
* @return TEntry|null
*/
protected function getEntryValueWithKey(string $key)
{
$return = null;
/** @var mixed $value */
$value = $this->getEntryValue();
if (is_array($value)) {
return $value[$key] ?? null;
}
if (is_object($value)) {
return $value->{$key} ?? null;
/** @var TEntry $return */
$return = $value[$key] ?? null;
} elseif (is_object($value)) {
/** @var TEntry $return */
$return = $value->{$key} ?? null;
}
return null;
return $return;
}
}
Loading

0 comments on commit a2e101b

Please sign in to comment.