diff --git a/.editorconfig b/.editorconfig index cf80b4e..230dd59 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,15 @@ insert_final_newline = true indent_style = space indent_size = 4 trim_trailing_whitespace = true + +[*.yml] +indent_size = 2 + +[*.yaml] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.gitattributes b/.gitattributes index bdd4ea2..dab2ae7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,7 @@ -/tests export-ignore \ No newline at end of file +* text=auto + +/.* export-ignore +/tests/ export-ignore + +/*.xml export-ignore +/*.xml.dist export-ignore diff --git a/.github/workflows/cs-fix.yml b/.github/workflows/cs-fix.yml new file mode 100644 index 0000000..0395b27 --- /dev/null +++ b/.github/workflows/cs-fix.yml @@ -0,0 +1,12 @@ +on: + push: + branches: + - '*' + +name: Fix Code Style + +jobs: + cs-fix: + permissions: + contents: write + uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25e9c79..3b13776 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,20 +3,18 @@ name: build on: push: pull_request: - schedule: - - cron: '0 0 * * *' jobs: test: - name: Build (${{matrix.php}}, ${{ matrix.os }}, ${{ matrix.stability }}) + name: Build (${{matrix.php}}, ${{ matrix.os }}, ${{ matrix.dependencies }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - php: [ '7.4', '8.0', '8.1' ] + php: ['8.1', '8.2', '8.3', '8.4'] os: [ ubuntu-latest ] - stability: [ prefer-lowest, prefer-stable ] + dependencies: [ lowest, highest ] steps: - name: Set Git To Use LF @@ -24,7 +22,7 @@ jobs: git config --global core.autocrlf false git config --global core.eol lf - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Install PHP Dependencies - name: Setup PHP ${{ matrix.php }} @@ -36,38 +34,30 @@ jobs: coverage: pcov tools: pecl ini-values: "memory_limit=-1" - - name: Validate Composer - run: composer validate - - name: Get Composer Cache Directory - # Docs: - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Restore Composer Cache - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer- - - name: Install dependencies with composer - if: matrix.php-version != '8.2' - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + - name: Setup problem matchers + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - name: Install dependencies with composer php 8.2 - if: matrix.php-version == '8.2' - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi --ignore-platform-reqs + - name: Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: Install dependencies with composer + uses: ramsey/composer-install@v3 + with: + dependency-versions: ${{ matrix.dependencies }} - # Execution - name: Execute Tests run: vendor/bin/phpunit --coverage-clover=coverage.clover - - name: Upload Coverage To Codecov - uses: codecov/codecov-action@v1 + + - name: Upload Coverage to Codecov + uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.clover fail_ci_if_error: false - - name: Upload coverage to Scrutinizer - continue-on-error: true # if is fork + + - name: Upload Coverage to Scrutinizer + continue-on-error: true uses: sudo-bot/action-scrutinizer@latest with: - cli-args: "--format=php-clover coverage.clover" \ No newline at end of file + cli-args: "--format=php-clover coverage.clover" diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0e288d1..4cf83c3 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -3,50 +3,36 @@ name: static analysis on: pull_request: push: - schedule: - - cron: '0 0 * * *' jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - + static-analysis: + name: PHP ${{ matrix.php }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: - os: - - ubuntu-latest - - php: - - "8.0" + php: [8.3] + os: [ubuntu-latest] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Install PHP + - name: Install PHP ${{ matrix.php }} uses: shivammathur/setup-php@v2 with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr + php-version: ${{ matrix.php }} + ini-values: error_reporting=E_ALL coverage: none - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- + - name: Setup problem matchers + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - name: Update composer - run: composer self-update + - name: Validate composer.json and composer.lock + run: composer validate --ansi --strict - name: Install dependencies with composer - run: composer update --with cycle/orm:^2.0 --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + uses: ramsey/composer-install@v3 - - name: Static analysis - run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle --php-version=8.0 | cs2pr --graceful-warnings --colorize + - name: Run Psalm Static Analysis + run: composer psalm:ci diff --git a/.gitignore b/.gitignore index 5a2d600..86fdd07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /.idea /composer.lock /vendor -/.phpunit.result.cache +/runtime diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..7bad12e --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,11 @@ +include(__DIR__ . '/src') + ->include(__FILE__) + ->allowRisky(true) + ->build(); diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 80835ed..d27b154 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,7 +14,7 @@ build: nodes: analysis: environment: - php: 8.0 + php: 8.1 tests: override: diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index dd8ece2..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,81 +0,0 @@ -preset: psr12 -risky: true - -version: 7 - -finder: - exclude: - - "tests" - not-name: - - "*.stub.txt" - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_separation - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals diff --git a/composer.json b/composer.json index 7acbc87..00cc68e 100644 --- a/composer.json +++ b/composer.json @@ -4,13 +4,15 @@ "license": "MIT", "description": "Utils for Cycle ORM Schema rendering", "require": { - "php": ">=7.4", - "cycle/orm": "1.2 - 2" + "php": ">=8.1", + "cycle/orm": "^2.0", + "symfony/polyfill-php83": "^1.31.0" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "spiral/code-style": "^1.0", - "vimeo/psalm": "^4.10|^5.1" + "phpunit/phpunit": "^10.5", + "spiral/code-style": "^2.2.2", + "spiral/dumper": "^3.3", + "vimeo/psalm": "^5.26.1 || ^6.8.9" }, "autoload": { "psr-4": { @@ -23,11 +25,12 @@ } }, "scripts": { - "test": [ - "phpcs --standard=phpcs.xml", - "psalm --no-cache", - "phpunit" - ] + "cs:diff": "php-cs-fixer fix --dry-run -v --diff --show-progress dots", + "cs:fix": "php-cs-fixer fix -v", + "psalm": "psalm", + "psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4", + "psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", + "test": "phpunit --color=always" }, "config": { "sort-packages": true diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index a81e173..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ./src - diff --git a/phpunit.xml b/phpunit.xml index 93cd098..6b84255 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,33 +1,39 @@ - - - + + ./tests/ + tests/Schema/Renderer/BaseTest.php - + src + + + + + + + - \ No newline at end of file + diff --git a/psalm.xml b/psalm.xml index 4e9226b..4d22794 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,4 +12,19 @@ + + + + + + + + + + + + + + + diff --git a/src/ConsoleRenderer/Formatter/PlainFormatter.php b/src/ConsoleRenderer/Formatter/PlainFormatter.php index bcd0eb0..32d216c 100644 --- a/src/ConsoleRenderer/Formatter/PlainFormatter.php +++ b/src/ConsoleRenderer/Formatter/PlainFormatter.php @@ -8,36 +8,43 @@ final class PlainFormatter implements Formatter { + #[\Override] public function title(string $title): string { - return str_pad($title, self::TITLE_LENGTH, ' ', STR_PAD_LEFT); + return \str_pad($title, self::TITLE_LENGTH, ' ', STR_PAD_LEFT); } + #[\Override] public function property(string $string): string { return $string; } + #[\Override] public function column(string $string): string { return $string; } + #[\Override] public function info(string $string): string { return $string; } + #[\Override] public function typecast(string $string): string { return $string; } + #[\Override] public function entity(string $string): string { return $string; } + #[\Override] public function error(string $string): string { return $string; diff --git a/src/ConsoleRenderer/Formatter/StyledFormatter.php b/src/ConsoleRenderer/Formatter/StyledFormatter.php index 6c4847b..215396a 100644 --- a/src/ConsoleRenderer/Formatter/StyledFormatter.php +++ b/src/ConsoleRenderer/Formatter/StyledFormatter.php @@ -21,36 +21,43 @@ final class StyledFormatter implements Formatter '' => "\033[36m", ]; + #[\Override] public function title(string $title): string { - return str_pad($title, self::TITLE_LENGTH, ' ', STR_PAD_LEFT); + return \str_pad($title, self::TITLE_LENGTH, ' ', STR_PAD_LEFT); } + #[\Override] public function property(string $string): string { return $this->colorize("{$string}"); } + #[\Override] public function column(string $string): string { return $this->colorize("{$string}"); } + #[\Override] public function info(string $string): string { return $this->colorize("{$string}"); } + #[\Override] public function typecast(string $string): string { return $this->colorize("{$string}"); } + #[\Override] public function entity(string $string): string { return $this->colorize("{$string}"); } + #[\Override] public function error(string $string): string { return $this->colorize("{$string}"); @@ -58,10 +65,10 @@ public function error(string $string): string private function colorize(string $string): string { - return str_replace( - array_keys(self::COLORS_MAP), - array_values(self::COLORS_MAP), - $string + return \str_replace( + \array_keys(self::COLORS_MAP), + \array_values(self::COLORS_MAP), + $string, ); } } diff --git a/src/ConsoleRenderer/OutputRenderer.php b/src/ConsoleRenderer/OutputRenderer.php index 1eb906a..c9cb652 100644 --- a/src/ConsoleRenderer/OutputRenderer.php +++ b/src/ConsoleRenderer/OutputRenderer.php @@ -10,6 +10,7 @@ class OutputRenderer implements SchemaRenderer { /** @var Renderer[] */ private array $renderers = []; + private Formatter $formatter; public function __construct(Formatter $formatter, array $renderers = []) @@ -25,6 +26,7 @@ final public function addRenderer(Renderer ...$renderers): void } } + #[\Override] final public function render(array $schema): string { $result = ''; @@ -39,9 +41,8 @@ private function renderRole(array $schema, string $role): string $rows = []; foreach ($this->renderers as $renderer) { - if ($row = $renderer->render($this->formatter, $schema, $role)) { - $rows[] = $row; - } + $row = $renderer->render($this->formatter, $schema, $role); + $row !== null and $row !== '' and $rows[] = $row; } return \implode($this->formatter::LINE_SEPARATOR, $rows); diff --git a/src/ConsoleRenderer/Renderer/ColumnsRenderer.php b/src/ConsoleRenderer/Renderer/ColumnsRenderer.php index 5f57667..92d33b5 100644 --- a/src/ConsoleRenderer/Renderer/ColumnsRenderer.php +++ b/src/ConsoleRenderer/Renderer/ColumnsRenderer.php @@ -10,6 +10,7 @@ class ColumnsRenderer implements Renderer { + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { $rows = []; @@ -30,7 +31,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $padding, $formatter->property('property'), $formatter->column('db.field'), - $formatter->typecast('typecast') + $formatter->typecast('typecast'), ); $types = $schema[SchemaInterface::TYPECAST] ?? []; @@ -40,14 +41,14 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $row = \sprintf( '%s%s -> %s', $padding, - $formatter->property((string)$property), - $formatter->column($field) + $formatter->property((string) $property), + $formatter->column($field), ); if ($typecast !== null && $typecast !== [] && $typecast !== '') { $row .= \sprintf( ' -> %s', - $formatter->typecast(\implode('::', (array)$typecast)) + $formatter->typecast(\implode('::', (array) $typecast)), ); } diff --git a/src/ConsoleRenderer/Renderer/CustomPropertiesRenderer.php b/src/ConsoleRenderer/Renderer/CustomPropertiesRenderer.php index e4339cb..714cf88 100644 --- a/src/ConsoleRenderer/Renderer/CustomPropertiesRenderer.php +++ b/src/ConsoleRenderer/Renderer/CustomPropertiesRenderer.php @@ -19,6 +19,7 @@ public function __construct(array $exclude) $this->exclude = $exclude; } + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { $customProperties = \array_diff(\array_keys($schema), $this->exclude); @@ -38,7 +39,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri '%s%s: %s', $formatter->title(' '), $property, - $formatter->typecast($this->printValue($data, $formatter)) + $formatter->typecast($this->printValue($data, $formatter)), ); } @@ -52,12 +53,12 @@ private function printValue($value, Formatter $formatter): string { $data = \trim(\var_export($value, true), '\''); $data = \array_map( - static fn (string $row): string => $formatter->title(' ') . $row, - \explode("\n", $data) + static fn(string $row): string => $formatter->title(' ') . $row, + \explode("\n", $data), ); return \ltrim( - \implode("\n", $data) + \implode("\n", $data), ); } } diff --git a/src/ConsoleRenderer/Renderer/KeysRenderer.php b/src/ConsoleRenderer/Renderer/KeysRenderer.php index 7af3226..92309cd 100644 --- a/src/ConsoleRenderer/Renderer/KeysRenderer.php +++ b/src/ConsoleRenderer/Renderer/KeysRenderer.php @@ -17,13 +17,14 @@ class KeysRenderer implements Renderer public function __construct( int $key = SchemaInterface::PRIMARY_KEY, string $title = 'Primary key', - bool $required = true + bool $required = true, ) { $this->title = $title; $this->key = $key; $this->required = $required; } + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { $keys = $schema[$this->key] ?? null; @@ -35,8 +36,8 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri } $keys = \array_map( - static fn (string $key) => $formatter->property($key), - (array)$keys + static fn(string $key) => $formatter->property($key), + (array) $keys, ); return $row . \implode(', ', $keys); diff --git a/src/ConsoleRenderer/Renderer/ListenersRenderer.php b/src/ConsoleRenderer/Renderer/ListenersRenderer.php index 62d8308..8a7548c 100644 --- a/src/ConsoleRenderer/Renderer/ListenersRenderer.php +++ b/src/ConsoleRenderer/Renderer/ListenersRenderer.php @@ -18,13 +18,14 @@ public function __construct(int $property, string $title) $this->title = $title; } + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { if (! isset($schema[$this->property])) { return null; } - $listeners = (array)($schema[$this->property] ?? []); + $listeners = (array) ($schema[$this->property] ?? []); if ($listeners === []) { return null; @@ -35,7 +36,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri ]; foreach ($listeners as $definition) { - $data = (array)$definition; + $data = (array) $definition; // Listener class $class = \is_string($data[0] ?? null) @@ -57,7 +58,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $row .= $formatter->info($this->printValue($value, $formatter)); $rows[] = $row; } - } elseif (is_string($args)) { + } elseif (\is_string($args)) { $rows[] = $formatter->title(' ') . ' - ' . $formatter->info($this->printValue($args, $formatter)); } else { $rows[] = $formatter->typecast($this->printValue($data, $formatter)); @@ -74,12 +75,12 @@ private function printValue($value, Formatter $formatter): string { $data = \trim(\var_export($value, true), '\''); $data = \array_map( - static fn (string $row): string => $formatter->title(' ') . $row, - \explode("\n", $data) + static fn(string $row): string => $formatter->title(' ') . $row, + \explode("\n", $data), ); return \ltrim( - \implode("\n", $data) + \implode("\n", $data), ); } } diff --git a/src/ConsoleRenderer/Renderer/MacrosRenderer.php b/src/ConsoleRenderer/Renderer/MacrosRenderer.php index 36f8d37..b47d7b9 100644 --- a/src/ConsoleRenderer/Renderer/MacrosRenderer.php +++ b/src/ConsoleRenderer/Renderer/MacrosRenderer.php @@ -7,6 +7,4 @@ /** * @deprecated use {@see ListenersRenderer} instead */ -class MacrosRenderer extends ListenersRenderer -{ -} +class MacrosRenderer extends ListenersRenderer {} diff --git a/src/ConsoleRenderer/Renderer/PropertyRenderer.php b/src/ConsoleRenderer/Renderer/PropertyRenderer.php index 61da161..ccbf130 100644 --- a/src/ConsoleRenderer/Renderer/PropertyRenderer.php +++ b/src/ConsoleRenderer/Renderer/PropertyRenderer.php @@ -20,6 +20,7 @@ public function __construct(int $property, string $title, bool $required = false $this->required = $required; } + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { $row = \sprintf('%s: ', $formatter->title($this->title)); @@ -40,7 +41,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri return \sprintf( '%s%s', $row, - $formatter->typecast($propertyValue) + $formatter->typecast($propertyValue), ); } @@ -48,11 +49,11 @@ private function convertArrayToString(Formatter $formatter, array $values): stri { $string = \implode( "\n", - \array_map(static fn ($property) => \sprintf( + \array_map(static fn($property) => \sprintf( ' %s%s', $formatter->title(' '), - $formatter->typecast($property) - ), $values) + $formatter->typecast($property), + ), $values), ); return \ltrim($string); diff --git a/src/ConsoleRenderer/Renderer/RelationsRenderer.php b/src/ConsoleRenderer/Renderer/RelationsRenderer.php index af80138..8f0b2ff 100644 --- a/src/ConsoleRenderer/Renderer/RelationsRenderer.php +++ b/src/ConsoleRenderer/Renderer/RelationsRenderer.php @@ -22,12 +22,12 @@ class RelationsRenderer implements Renderer Relation::MORPHED_HAS_ONE => 'morphed has one', Relation::MORPHED_HAS_MANY => 'morphed has many', ]; - private const STR_PREFETCH_MODE = [ Relation::LOAD_PROMISE => 'lazy', Relation::LOAD_EAGER => 'eager', ]; + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { $title = \sprintf('%s:', $formatter->title('Relations')); @@ -47,10 +47,14 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $innerKey = $relSchema[Relation::INNER_KEY] ?? '?'; $outerKey = $relSchema[Relation::OUTER_KEY] ?? '?'; $where = $relSchema[Relation::WHERE] ?? []; - $cascade = $relSchema[Relation::CASCADE] ?? null; - $cascadeStr = $cascade ? 'cascaded' : 'not cascaded'; + $cascade = $relSchema[Relation::CASCADE] ?? false; + $cascadeStr = $cascade === true ? 'cascaded' : 'not cascaded'; $nullable = $relSchema[Relation::NULLABLE] ?? null; - $nullableStr = $nullable ? 'nullable' : ($nullable === false ? 'not null' : 'n/a'); + $nullableStr = match ($nullable) { + true => 'nullable', + false => 'not null', + default => 'n/a', + }; $morphKey = $relSchema[Relation::MORPH_KEY] ?? null; // Many-To-Many relation(s) options @@ -65,14 +69,14 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $formatter->entity($role), $formatter->property($field), $type, - $formatter->entity($target) + $formatter->entity($target), ); if ($morphKey !== null) { $row .= \sprintf( ', %s: %s', $formatter->title('morphed key'), - $this->renderKeys($formatter, $morphKey) + $this->renderKeys($formatter, $morphKey), ); } @@ -82,7 +86,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri ' %s %s.%s <=', $nullableStr, $formatter->entity($role), - $this->renderKeys($formatter, $innerKey) + $this->renderKeys($formatter, $innerKey), ); if ($mmEntity !== null) { @@ -91,7 +95,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $formatter->entity($mmEntity), $this->renderKeys($formatter, $mmInnerKey), $formatter->entity($mmEntity), - $this->renderKeys($formatter, $mmOuterKey) + $this->renderKeys($formatter, $mmOuterKey), ); } @@ -99,30 +103,30 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri $rows[] = $row . \sprintf( '=> %s.%s', $formatter->entity($target), - $this->renderKeys($formatter, $outerKey) + $this->renderKeys($formatter, $outerKey), ); - if (count($where)) { + if (\count($where)) { $rows[] = \sprintf( '%s: %s', $formatter->title('Where'), \str_replace( ["\r\n", "\n"], $formatter::LINE_SEPARATOR . ' ', - $formatter::LINE_SEPARATOR . print_r($where, true) - ) + $formatter::LINE_SEPARATOR . \print_r($where, true), + ), ); } - if (count($mmWhere)) { + if (\count($mmWhere)) { $rows[] = \sprintf( '%s: %s', $formatter->title('Through where'), \str_replace( ["\r\n", "\n"], $formatter::LINE_SEPARATOR . ' ', - $formatter::LINE_SEPARATOR . print_r($mmWhere, true) - ) + $formatter::LINE_SEPARATOR . \print_r($mmWhere, true), + ), ); } } @@ -135,18 +139,18 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri */ private function renderKeys(Formatter $formatter, $keys): string { - $keys = (array)$keys; + $keys = (array) $keys; $braces = \count($keys) > 1; $keys = \array_map( - static fn (string $key) => $formatter->property($key), - $keys + static fn(string $key) => $formatter->property($key), + $keys, ); return \sprintf( '%s%s%s', $braces ? '[' : '', \implode(', ', $keys), - $braces ? ']' : '' + $braces ? ']' : '', ); } } diff --git a/src/ConsoleRenderer/Renderer/TitleRenderer.php b/src/ConsoleRenderer/Renderer/TitleRenderer.php index f45800b..5ae3817 100644 --- a/src/ConsoleRenderer/Renderer/TitleRenderer.php +++ b/src/ConsoleRenderer/Renderer/TitleRenderer.php @@ -10,6 +10,7 @@ class TitleRenderer implements Renderer { + #[\Override] public function render(Formatter $formatter, array $schema, string $role): ?string { $database = $schema[SchemaInterface::DATABASE] ?? ''; @@ -19,7 +20,7 @@ public function render(Formatter $formatter, array $schema, string $role): ?stri '%s :: %s.%s', $formatter->entity("[{$role}]"), $formatter->column($database), - $formatter->column($table) + $formatter->column($table), ); } } diff --git a/src/MermaidRenderer/Column.php b/src/MermaidRenderer/Column.php index e054599..19f6dc1 100644 --- a/src/MermaidRenderer/Column.php +++ b/src/MermaidRenderer/Column.php @@ -31,7 +31,6 @@ public function __toString(): string /** * @param Ttype $typecast * - * @return string */ private function formatTypecast($typecast): string { diff --git a/src/MermaidRenderer/Entity/EntityInterface.php b/src/MermaidRenderer/Entity/EntityInterface.php index bc10623..017ddb0 100644 --- a/src/MermaidRenderer/Entity/EntityInterface.php +++ b/src/MermaidRenderer/Entity/EntityInterface.php @@ -6,6 +6,4 @@ use Cycle\Schema\Renderer\MermaidRenderer\Stringable; -interface EntityInterface extends Stringable -{ -} +interface EntityInterface extends Stringable {} diff --git a/src/MermaidRenderer/Entity/EntityRelation.php b/src/MermaidRenderer/Entity/EntityRelation.php index f80f538..ea4c579 100644 --- a/src/MermaidRenderer/Entity/EntityRelation.php +++ b/src/MermaidRenderer/Entity/EntityRelation.php @@ -20,7 +20,7 @@ public function addRelation(Relation $relation): void public function __toString(): string { - $relations = \array_map(function (Relation $relation) { + $relations = \array_map(static function (Relation $relation) { return (string) $relation; }, $this->relations); diff --git a/src/MermaidRenderer/Entity/EntityTable.php b/src/MermaidRenderer/Entity/EntityTable.php index 23b0829..5486408 100644 --- a/src/MermaidRenderer/Entity/EntityTable.php +++ b/src/MermaidRenderer/Entity/EntityTable.php @@ -16,7 +16,6 @@ class %s { %s } BLOCK; - public const INDENT = ' '; private string $title; @@ -48,7 +47,7 @@ public function addAnnotation(Annotation $annotation): void public function __toString(): string { - $columns = \array_map(function (Stringable $column) { + $columns = \array_map(static function (Stringable $column) { return (string) $column; }, $this->columns); diff --git a/src/MermaidRenderer/MermaidRenderer.php b/src/MermaidRenderer/MermaidRenderer.php index 19f8a13..6ec7956 100644 --- a/src/MermaidRenderer/MermaidRenderer.php +++ b/src/MermaidRenderer/MermaidRenderer.php @@ -36,6 +36,7 @@ final class MermaidRenderer implements SchemaRenderer { use StringFormatter; + #[\Override] public function render(array $schema): string { $class = new ClassDiagram(); @@ -55,13 +56,13 @@ public function render(array $schema): string if (\strpos($key, ':') !== false) { $entityTable->addAnnotation( - new Annotation($key) + new Annotation($key), ); } foreach ($value[SchemaInterface::COLUMNS] as $column) { $entityTable->addColumn( - new Column($value[SchemaInterface::TYPECAST][$column] ?? 'string', $column) + new Column($value[SchemaInterface::TYPECAST][$column] ?? 'string', $column), ); } @@ -81,26 +82,26 @@ public function render(array $schema): string switch ($relation[SchemaRelation::TYPE]) { case SchemaRelation::HAS_ONE: $entityTable->addMethod( - new HasOneMethod($relationKey, $target) + new HasOneMethod($relationKey, $target), ); $entityRelation->addRelation( - new HasOneRelation($role, $target, $relationKey, $isNullable) + new HasOneRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::HAS_MANY: $entityTable->addMethod( - new HasManyMethod($relationKey, $target) + new HasManyMethod($relationKey, $target), ); $entityRelation->addRelation( - new HasManyRelation($role, $target, $relationKey, $isNullable) + new HasManyRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::BELONGS_TO: $entityTable->addMethod( - new BelongsToMethod($relationKey, $target) + new BelongsToMethod($relationKey, $target), ); $entityRelation->addRelation( - new BelongsToRelation($role, $target, $relationKey, $isNullable) + new BelongsToRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::MANY_TO_MANY: @@ -112,49 +113,49 @@ public function render(array $schema): string } $entityTable->addMethod( - new ManyToManyMethod($relationKey, $target) + new ManyToManyMethod($relationKey, $target), ); $entityRelation->addRelation( - new ManyToManyRelation($role, $target, $relationKey, $isNullable) + new ManyToManyRelation($role, $target, $relationKey, $isNullable), ); $entityRelation->addRelation( - new Relation($throughEntity, $role, "$role.$relationKey", '..>', $isNullable) + new Relation($throughEntity, $role, "$role.$relationKey", '..>', $isNullable), ); $entityRelation->addRelation( - new Relation($throughEntity, $target, "$role.$relationKey", '..>', $isNullable) + new Relation($throughEntity, $target, "$role.$relationKey", '..>', $isNullable), ); } break; case SchemaRelation::REFERS_TO: $entityTable->addMethod( - new RefersToMethod($relationKey, $target) + new RefersToMethod($relationKey, $target), ); $entityRelation->addRelation( - new RefersToRelation($role, $target, $relationKey, $isNullable) + new RefersToRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::MORPHED_HAS_MANY: $entityTable->addMethod( - new MorphedHasManyMethod($relationKey, $target) + new MorphedHasManyMethod($relationKey, $target), ); $entityRelation->addRelation( - new MorphedHasManyRelation($role, $target, $relationKey, $isNullable) + new MorphedHasManyRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::MORPHED_HAS_ONE: $entityTable->addMethod( - new MorphedHasOneMethod($relationKey, $target) + new MorphedHasOneMethod($relationKey, $target), ); $entityRelation->addRelation( - new MorphedHasOneRelation($role, $target, $relationKey, $isNullable) + new MorphedHasOneRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::BELONGS_TO_MORPHED: $entityTable->addMethod( - new BelongsToMorphedMethod($relationKey, $target) + new BelongsToMorphedMethod($relationKey, $target), ); $entityRelation->addRelation( - new BelongsToMorphedRelation($role, $target, $relationKey, $isNullable) + new BelongsToMorphedRelation($role, $target, $relationKey, $isNullable), ); break; case SchemaRelation::EMBEDDED: @@ -162,10 +163,10 @@ public function render(array $schema): string $prop = isset($methodTarget[2]) ? $methodTarget[2] . '_prop' : $target; $entityTable->addMethod( - new EmbeddedMethod($prop, $relation[SchemaRelation::TARGET]) + new EmbeddedMethod($prop, $relation[SchemaRelation::TARGET]), ); $entityRelation->addRelation( - new EmbeddedRelation($role, $target, $prop, $isNullable) + new EmbeddedRelation($role, $target, $prop, $isNullable), ); break; default: @@ -175,13 +176,13 @@ public function render(array $schema): string foreach ($value[SchemaInterface::CHILDREN] ?? [] as $children) { $entityRelation->addRelation( - new SingleInheritanceRelation($role, $children, false) + new SingleInheritanceRelation($role, $children, false), ); } if (isset($constants['PARENT'], $value[$constants['PARENT']])) { $entityRelation->addRelation( - new JoinedInheritanceRelation($value[$constants['PARENT']], $role, false) + new JoinedInheritanceRelation($value[$constants['PARENT']], $role, false), ); } @@ -189,6 +190,6 @@ public function render(array $schema): string $class->addEntity($entityRelation); } - return (string)$class; + return (string) $class; } } diff --git a/src/MermaidRenderer/Method.php b/src/MermaidRenderer/Method.php index 050bae0..4f599f6 100644 --- a/src/MermaidRenderer/Method.php +++ b/src/MermaidRenderer/Method.php @@ -23,7 +23,7 @@ public function __toString(): string '%s(%s: %s)', $this->name, $this->abbreviation, - $this->target + $this->target, ); } } diff --git a/src/MermaidRenderer/Relation.php b/src/MermaidRenderer/Relation.php index 263736c..9fb9bac 100644 --- a/src/MermaidRenderer/Relation.php +++ b/src/MermaidRenderer/Relation.php @@ -21,7 +21,7 @@ public function __construct( string $children, string $comment, string $arrow, - bool $isNullable + bool $isNullable, ) { $this->parent = $this->resolveString($parent); $this->children = $this->resolveString($children); diff --git a/src/MermaidRenderer/RoleAliasCollection.php b/src/MermaidRenderer/RoleAliasCollection.php index b9390de..de4207c 100644 --- a/src/MermaidRenderer/RoleAliasCollection.php +++ b/src/MermaidRenderer/RoleAliasCollection.php @@ -41,11 +41,10 @@ public function getAlias(string $role): string /** * @param non-empty-string $role * - * @return string */ private function makeAlias(string $role): string { - $role = \preg_replace('/[^a-z0-9_]/u', '_', $role); + $role = (string) \preg_replace('/[^a-z0-9_]/u', '_', $role); $oldRole = $role; $counter = 0; diff --git a/src/MermaidRenderer/Schema/ClassDiagram.php b/src/MermaidRenderer/Schema/ClassDiagram.php index e6885f1..06d9cdd 100644 --- a/src/MermaidRenderer/Schema/ClassDiagram.php +++ b/src/MermaidRenderer/Schema/ClassDiagram.php @@ -17,13 +17,14 @@ classDiagram private array $entities = []; - public function __toString(): string + #[\Override] + public function addEntity(EntityInterface $entity): void { - return sprintf(self::DIAGRAM, \implode("\n", $this->entities)); + $this->entities[] = $entity; } - public function addEntity(EntityInterface $entity): void + public function __toString(): string { - $this->entities[] = $entity; + return \sprintf(self::DIAGRAM, \implode("\n", $this->entities)); } } diff --git a/src/MermaidRenderer/StringFormatter.php b/src/MermaidRenderer/StringFormatter.php index 91eb6a0..c22381d 100644 --- a/src/MermaidRenderer/StringFormatter.php +++ b/src/MermaidRenderer/StringFormatter.php @@ -9,7 +9,7 @@ trait StringFormatter private function resolveString(string $value): string { if (\preg_match('/[^_a-zA-Z0-9]/u', $value)) { - $value = \preg_replace('/[^a-z0-9_]/u', '_', $value); + $value = (string) \preg_replace('/[^a-z0-9_]/u', '_', $value); } return $value; @@ -22,6 +22,6 @@ private function getClassShortName($class): string { $className = \is_object($class) ? \get_class($class) : $class; - return \substr($className, ((int)\strrpos($className, '\\')) + 1); + return \substr($className, ((int) \strrpos($className, '\\')) + 1); } } diff --git a/src/OutputSchemaRenderer.php b/src/OutputSchemaRenderer.php index 2531c21..2d4cd1b 100644 --- a/src/OutputSchemaRenderer.php +++ b/src/OutputSchemaRenderer.php @@ -23,7 +23,6 @@ final class OutputSchemaRenderer extends OutputRenderer { public const FORMAT_PLAIN_TEXT = 0; public const FORMAT_CONSOLE_COLOR = 1; - protected const DEFAULT_PROPERTY_LIST = [ 'ROLE' => 'Role', 'ENTITY' => 'Entity', @@ -46,9 +45,9 @@ public function __construct(int $format = self::FORMAT_CONSOLE_COLOR, ?Constants new TitleRenderer(), // Default properties renderer (Without extra logic) - ...array_map(static function ($property, string $title) { + ...\array_map(static function ($property, string $title) { return new PropertyRenderer($property, $title); - }, array_keys($properties), $properties), + }, \array_keys($properties), $properties), new KeysRenderer(SchemaInterface::PRIMARY_KEY, 'Primary key', true), ]); @@ -94,7 +93,7 @@ private function getOrmProperties(array $constants): array { $result = []; foreach ($constants as $name => $value) { - if (!array_key_exists($name, self::DEFAULT_PROPERTY_LIST)) { + if (!\array_key_exists($name, self::DEFAULT_PROPERTY_LIST)) { continue; } $result[$value] = self::DEFAULT_PROPERTY_LIST[$name]; diff --git a/src/PhpFileRenderer/Exporter/ArrayBlock.php b/src/PhpFileRenderer/Exporter/ArrayBlock.php index 2e02b74..e7bf2c6 100644 --- a/src/PhpFileRenderer/Exporter/ArrayBlock.php +++ b/src/PhpFileRenderer/Exporter/ArrayBlock.php @@ -20,12 +20,14 @@ public function __construct(array $value, array $replaceKeys = [], array $replac $this->replaceValues = $replaceValues; } + #[\Override] final public function setIndentLevel(int $indentLevel = 0): self { $this->indentLevel = $indentLevel; return $this; } + #[\Override] final public function toString(): string { $result = []; @@ -54,10 +56,10 @@ final public function toString(): string protected function wrapItem($key, $value): ArrayItem { $item = isset($this->replaceKeys[$key]) - ? new ArrayItem($value, (string)$this->replaceKeys[$key], false) - : new ArrayItem($value, (string)$key, true); + ? new ArrayItem($value, (string) $this->replaceKeys[$key], false) + : new ArrayItem($value, (string) $key, true); - if (is_scalar($value) && isset($this->replaceValues[$key][$value])) { + if (\is_scalar($value) && isset($this->replaceValues[$key][$value])) { $item->setValue($this->replaceValues[$key][$value], false); } return $item; diff --git a/src/PhpFileRenderer/Exporter/ArrayItem.php b/src/PhpFileRenderer/Exporter/ArrayItem.php index de157e1..3d07b28 100644 --- a/src/PhpFileRenderer/Exporter/ArrayItem.php +++ b/src/PhpFileRenderer/Exporter/ArrayItem.php @@ -13,6 +13,7 @@ final class ArrayItem implements ExporterItem, Indentable /** @var mixed */ private $value; + private bool $wrapValue = true; private bool $wrapKey; private int $indentLevel = 0; @@ -20,19 +21,21 @@ final class ArrayItem implements ExporterItem, Indentable /** * @param mixed $value */ - public function __construct($value, string $key = null, bool $wrapKey = true) + public function __construct($value, ?string $key = null, bool $wrapKey = true) { $this->key = $key; $this->value = $value; $this->wrapKey = $wrapKey; } + #[\Override] public function setIndentLevel(int $indentLevel = 0): self { $this->indentLevel = $indentLevel; return $this; } + #[\Override] public function toString(): string { $result = \str_repeat(self::INDENT, $this->indentLevel); diff --git a/src/PhpFileRenderer/Exporter/Rendering/ArrayRenderer.php b/src/PhpFileRenderer/Exporter/Rendering/ArrayRenderer.php index 3cf53d2..a315d01 100644 --- a/src/PhpFileRenderer/Exporter/Rendering/ArrayRenderer.php +++ b/src/PhpFileRenderer/Exporter/Rendering/ArrayRenderer.php @@ -14,7 +14,7 @@ public static function render(array $value, int $indentLevel = 0): string $inline = $aiKeys && self::isScalarArrayValues($value); if ($inline) { $result = self::renderArrayInline($value, !$aiKeys); - if (strlen($result) <= ExporterItem::MAX_LINE_LENGTH) { + if (\strlen($result) <= ExporterItem::MAX_LINE_LENGTH) { return $result; } } @@ -35,7 +35,7 @@ private static function renderArrayInline(array $value, bool $withKeys = true): foreach ($value as $key => $item) { $str = ''; if (!$item instanceof self && $withKeys) { - $str .= is_int($key) ? "{$key} => " : "'{$key}' => "; + $str .= \is_int($key) ? "{$key} => " : "'{$key}' => "; } $elements[] = $str . self::renderValue($item); } @@ -52,7 +52,7 @@ private static function renderArrayBlock(array $value, bool $withKeys = true, in if ($item instanceof Indentable) { $item->setIndentLevel($indentLevel + 1); } elseif ($withKeys) { - $result .= is_int($key) ? "{$key} => " : "'{$key}' => "; + $result .= \is_int($key) ? "{$key} => " : "'{$key}' => "; } $result .= self::renderValue($item, true, $indentLevel + 1) . ','; } @@ -61,13 +61,13 @@ private static function renderArrayBlock(array $value, bool $withKeys = true, in private static function isAutoIncrementedKeys(array $array): bool { - return count($array) === 0 || array_keys($array) === range(0, count($array) - 1); + return \count($array) === 0 || \array_keys($array) === \range(0, \count($array) - 1); } private static function isScalarArrayValues(array $array): bool { foreach ($array as $value) { - if (!is_scalar($value)) { + if (!\is_scalar($value)) { return false; } } diff --git a/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php b/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php index 529a2f7..3808bf6 100644 --- a/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php +++ b/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php @@ -16,20 +16,20 @@ public static function render($value, bool $wrapValue = true, int $indentLevel = switch (true) { case $value === null: return 'null'; - case is_bool($value): + case \is_bool($value): return $value ? 'true' : 'false'; - case is_array($value): + case \is_array($value): return ArrayRenderer::render($value, $indentLevel); case $value instanceof ExporterItem: return $value->toString(); - case !$wrapValue || is_int($value): - return (string)$value; + case !$wrapValue || \is_int($value): + return (string) $value; case \is_string($value) && \strpos($value, '\\') !== false && \class_exists($value): return "$value::class"; - case is_string($value): - return "'" . addslashes($value) . "'"; + case \is_string($value): + return "'" . \addslashes($value) . "'"; default: - return "unserialize('" . addslashes(serialize($value)) . "')"; + return "unserialize('" . \addslashes(\serialize($value)) . "')"; } } } diff --git a/src/PhpFileRenderer/Item/RelationBlock.php b/src/PhpFileRenderer/Item/RelationBlock.php index 21034d7..f84493a 100644 --- a/src/PhpFileRenderer/Item/RelationBlock.php +++ b/src/PhpFileRenderer/Item/RelationBlock.php @@ -37,10 +37,11 @@ class RelationBlock extends ArrayBlock * @param int|string $key * @param mixed $value */ + #[\Override] protected function wrapItem($key, $value): ArrayItem { $item = parent::wrapItem($key, $value); - if ($key === Relation::SCHEMA && is_array($value)) { + if ($key === Relation::SCHEMA && \is_array($value)) { $item->setValue(new self($value, $this->getReplaceKeys()), false); } return $item; @@ -57,7 +58,7 @@ private function getReplaceKeys(): array } $constants = (new \ReflectionClass(Relation::class))->getConstants(); foreach ($constants as $name => $value) { - if (!in_array($name, self::RELATION_SCHEMA_KEYS, true) || array_key_exists($value, $result)) { + if (!\in_array($name, self::RELATION_SCHEMA_KEYS, true) || \array_key_exists($value, $result)) { continue; } $result[$value] = 'Relation::' . $name; diff --git a/src/PhpFileRenderer/Item/RelationsBlock.php b/src/PhpFileRenderer/Item/RelationsBlock.php index fe8b8a6..5ba11a9 100644 --- a/src/PhpFileRenderer/Item/RelationsBlock.php +++ b/src/PhpFileRenderer/Item/RelationsBlock.php @@ -16,7 +16,6 @@ class RelationsBlock extends ArrayBlock Relation::SCHEMA => 'Relation::SCHEMA', Relation::LOAD => 'Relation::LOAD', ]; - private const OPTION_VALUES = [ Relation::LOAD => [ Relation::LOAD_PROMISE => 'Relation::LOAD_PROMISE', @@ -38,10 +37,11 @@ class RelationsBlock extends ArrayBlock * @param int|string $key * @param mixed $value */ + #[\Override] protected function wrapItem($key, $value): ArrayItem { $item = parent::wrapItem($key, $value); - if (is_array($value)) { + if (\is_array($value)) { $item->setValue(new RelationBlock($value, self::OPTION_KEYS, self::OPTION_VALUES), false); } return $item; diff --git a/src/PhpFileRenderer/Item/RoleBlock.php b/src/PhpFileRenderer/Item/RoleBlock.php index 0afcb81..888c9f5 100644 --- a/src/PhpFileRenderer/Item/RoleBlock.php +++ b/src/PhpFileRenderer/Item/RoleBlock.php @@ -14,10 +14,11 @@ class RoleBlock extends ArrayBlock * @param int|string $key * @param mixed $value */ + #[\Override] protected function wrapItem($key, $value): ArrayItem { $item = parent::wrapItem($key, $value); - if ($key === SchemaInterface::RELATIONS && is_array($value)) { + if ($key === SchemaInterface::RELATIONS && \is_array($value)) { $item->setValue(new RelationsBlock($value), false); } return $item; diff --git a/src/PhpSchemaRenderer.php b/src/PhpSchemaRenderer.php index 8d685d5..89c25de 100644 --- a/src/PhpSchemaRenderer.php +++ b/src/PhpSchemaRenderer.php @@ -21,6 +21,7 @@ class PhpSchemaRenderer implements SchemaRenderer 'Cycle\ORM\SchemaInterface as Schema', ]; + #[\Override] final public function render(array $schema): string { $result = "wrapRoleSchema($roleSchema), $role, - true + true, ); $items[] = $item->setIndentLevel(); } @@ -49,7 +50,7 @@ protected function wrapRoleSchema(array $roleSchema): ExporterItem { return new RoleBlock( $roleSchema, - $this->getSchemaConstants() + $this->getSchemaConstants(), ); } @@ -58,12 +59,12 @@ protected function wrapRoleSchema(array $roleSchema): ExporterItem */ final protected function getSchemaConstants(): array { - $result = array_filter( + $result = \array_filter( (new \ReflectionClass(SchemaInterface::class))->getConstants(), - static fn ($value): bool => is_int($value) + static fn($value): bool => \is_int($value), ); - $result = array_flip($result); - array_walk($result, static function (string &$name): void { + $result = \array_flip($result); + \array_walk($result, static function (string &$name): void { $name = "Schema::$name"; }); return $result; diff --git a/src/SchemaConstants.php b/src/SchemaConstants.php index 38bf730..2ba8d36 100644 --- a/src/SchemaConstants.php +++ b/src/SchemaConstants.php @@ -8,11 +8,12 @@ class SchemaConstants implements ConstantsInterface { + #[\Override] public function all(): array { - return array_filter( + return \array_filter( (new \ReflectionClass(SchemaInterface::class))->getConstants(), - 'is_int' + 'is_int', ); } } diff --git a/src/SchemaToArrayConverter.php b/src/SchemaToArrayConverter.php index 63ec0b7..adf9d24 100644 --- a/src/SchemaToArrayConverter.php +++ b/src/SchemaToArrayConverter.php @@ -20,7 +20,6 @@ public function __construct(?ConstantsInterface $constants = null) } /** - * @param SchemaInterface $schema * @param array $customProperties * * @return array> @@ -28,13 +27,13 @@ public function __construct(?ConstantsInterface $constants = null) public function convert(SchemaInterface $schema, array $customProperties = []): array { // For CycleORM >= 2.x - if (method_exists($schema, 'toArray')) { + if (\method_exists($schema, 'toArray')) { return $schema->toArray(); } $result = []; - $properties = array_merge($this->constants, $customProperties); + $properties = \array_merge($this->constants, $customProperties); foreach ($schema->getRoles() as $role) { foreach ($properties as $property) { diff --git a/tests/Schema/Renderer/ConsoleRenderer/Renderer/CustomPropertiesRendererTest.php b/tests/Schema/Renderer/ConsoleRenderer/Renderer/CustomPropertiesRendererTest.php index f37e9bb..88f89de 100644 --- a/tests/Schema/Renderer/ConsoleRenderer/Renderer/CustomPropertiesRendererTest.php +++ b/tests/Schema/Renderer/ConsoleRenderer/Renderer/CustomPropertiesRendererTest.php @@ -9,19 +9,14 @@ use Cycle\Schema\Renderer\ConsoleRenderer\Renderer\CustomPropertiesRenderer; use Cycle\Schema\Renderer\Tests\BaseTest; use Cycle\Schema\Renderer\Tests\Fixture\User; +use PHPUnit\Framework\Attributes\RequiresPhp; class CustomPropertiesRendererTest extends BaseTest { private Formatter $formatter; - protected function setUp(): void - { - parent::setUp(); - - $this->formatter = new PlainFormatter(); - } - - public function testCustomPropertiesShouldBeRendered() + #[RequiresPhp('>= 8.2.0')] + public function testCustomPropertiesShouldBeRendered(): void { $renderer = new CustomPropertiesRenderer(['bar', 'baz']); @@ -45,7 +40,7 @@ public function testCustomPropertiesShouldBeRendered() array: array ( 'foo' => 'bar', ) - object: Cycle\Schema\Renderer\Tests\Fixture\User::__set_state(array( + object: \Cycle\Schema\Renderer\Tests\Fixture\User::__set_state(array( )) bool: false OUTPUT @@ -53,4 +48,11 @@ public function testCustomPropertiesShouldBeRendered() $result ); } + + protected function setUp(): void + { + parent::setUp(); + + $this->formatter = new PlainFormatter(); + } } diff --git a/tests/Schema/Renderer/ConsoleRenderer/Renderer/MacrosRendererTest.php b/tests/Schema/Renderer/ConsoleRenderer/Renderer/ListenersRendererTest.php similarity index 100% rename from tests/Schema/Renderer/ConsoleRenderer/Renderer/MacrosRendererTest.php rename to tests/Schema/Renderer/ConsoleRenderer/Renderer/ListenersRendererTest.php index f2f2d72..2a4383a 100644 --- a/tests/Schema/Renderer/ConsoleRenderer/Renderer/MacrosRendererTest.php +++ b/tests/Schema/Renderer/ConsoleRenderer/Renderer/ListenersRendererTest.php @@ -13,13 +13,6 @@ final class ListenersRendererTest extends BaseTest { private Formatter $formatter; - protected function setUp(): void - { - parent::setUp(); - - $this->formatter = new PlainFormatter(); - } - public function testRenderNotExistsProperty() { $renderer = new ListenersRenderer(1, 'Foo'); @@ -93,4 +86,11 @@ public function testRenderAssocArrayProperty() $result ); } + + protected function setUp(): void + { + parent::setUp(); + + $this->formatter = new PlainFormatter(); + } }