diff --git a/.github/workflows/deptrac.yml b/.github/workflows/deptrac.yml index 4f59efe..c7f257e 100644 --- a/.github/workflows/deptrac.yml +++ b/.github/workflows/deptrac.yml @@ -31,7 +31,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' tools: phive extensions: intl, json, mbstring, xml coverage: none @@ -69,5 +69,7 @@ jobs: - name: Trace dependencies run: | - sudo phive --no-progress install --global --trust-gpg-keys B8F640134AB1782E,A98E898BB53EB748 qossmic/deptrac - deptrac analyze --cache-file=build/deptrac.cache + composer require --dev qossmic/deptrac-shim + vendor/bin/deptrac analyze --cache-file=build/deptrac.cache + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/infection.yml b/.github/workflows/infection.yml index 80b5272..5828e3f 100644 --- a/.github/workflows/infection.yml +++ b/.github/workflows/infection.yml @@ -31,7 +31,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' tools: infection, phpunit extensions: intl, json, mbstring, gd, xml, sqlite3 coverage: xdebug diff --git a/.github/workflows/phpcpd.yml b/.github/workflows/phpcpd.yml index d413e36..c755c44 100644 --- a/.github/workflows/phpcpd.yml +++ b/.github/workflows/phpcpd.yml @@ -27,7 +27,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' tools: phpcpd extensions: dom, mbstring coverage: none diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml index 365c377..d1ea6b1 100644 --- a/.github/workflows/phpcsfixer.yml +++ b/.github/workflows/phpcsfixer.yml @@ -27,7 +27,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' extensions: json, tokenizer coverage: none env: diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index a395b67..84f640a 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['8.2'] steps: - name: Checkout diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 7a56acc..cdbdbaf 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -25,7 +25,7 @@ jobs: if: "!contains(github.event.head_commit.message, '[ci skip]')" strategy: matrix: - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['8.2'] steps: - name: Checkout @@ -61,12 +61,12 @@ jobs: fi - name: Test with PHPUnit - run: vendor/bin/phpunit --verbose --coverage-text + run: vendor/bin/phpunit --coverage-text env: TERM: xterm-256color TACHYCARDIA_MONITOR_GA: enabled - - if: matrix.php-versions == '8.0' + - if: matrix.php-versions == '8.2' name: Run Coveralls continue-on-error: true run: | diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 7cda9ed..42802b0 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -31,7 +31,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' tools: phpstan, phpunit extensions: intl, json, mbstring, xml coverage: none diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index a4fde4f..b7add1c 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['8.2'] steps: - name: Checkout diff --git a/.github/workflows/unused.yml b/.github/workflows/unused.yml index ad4adad..6ac4a17 100644 --- a/.github/workflows/unused.yml +++ b/.github/workflows/unused.yml @@ -29,7 +29,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' tools: composer, composer-unused extensions: intl, json, mbstring, xml coverage: none diff --git a/psalm.xml b/psalm.xml index 386f4dc..47cd59e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -7,6 +7,8 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="psalm_autoload.php" cacheDirectory="build/psalm/" + findUnusedBaselineEntry="true" + findUnusedCode="false" > diff --git a/psalm_autoload.php b/psalm_autoload.php index 5a25347..4c33092 100644 --- a/psalm_autoload.php +++ b/psalm_autoload.php @@ -5,11 +5,16 @@ require __DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php'; $helperDirs = [ + 'app/Helpers', 'vendor/codeigniter4/framework/system/Helpers', ]; foreach ($helperDirs as $dir) { $dir = __DIR__ . '/' . $dir; + if (! is_dir($dir)) { + continue; + } + chdir($dir); foreach (glob('*_helper.php') as $filename) { @@ -18,3 +23,5 @@ require_once $filePath; } } + +chdir(__DIR__); diff --git a/src/Traits/EntityTrait.php b/src/Traits/EntityTrait.php index c23e502..211fbb2 100644 --- a/src/Traits/EntityTrait.php +++ b/src/Traits/EntityTrait.php @@ -59,6 +59,7 @@ public function __isset(string $key): bool // Convert the key to table format $tableName = plural(strtolower($key)); + // Check for a matching table return isset($schema->tables->{$tableName}); } @@ -81,7 +82,7 @@ public function __call(string $name, array $arguments) $verb = false; foreach ($verbs as $test) { - if (strpos($name, $test) === 0) { + if (str_starts_with($name, $test)) { $verb = $test; break; } @@ -242,12 +243,10 @@ protected function _set(string $tableName, ?array $keys = null): bool switch ($relation->type) { // WIP - need to decide about adding and detaching case 'hasMany': - break; // Delete entries from the pivot table case 'manyToMany': - // Get the pivot table info $pivotTable = $relation->pivots[0][2]; $pivotId = $relation->pivots[0][3]; @@ -297,12 +296,10 @@ protected function _add(string $tableName, array $keys): bool switch ($relation->type) { // WIP - need to decide about attaching versus adding case 'hasMany': - break; // Add entries to the pivot table case 'manyToMany': - // Get the pivot table info $pivotTable = $relation->pivots[0][2]; $pivotId = $relation->pivots[0][3]; @@ -356,12 +353,10 @@ protected function _remove(string $tableName, array $keys): bool switch ($relation->type) { // WIP - need to decide about detaching versus deleting case 'hasMany': - break; // Delete entries from the pivot table case 'manyToMany': - // Get the pivot table info $pivotTable = $relation->pivots[0][2]; $pivotId = $relation->pivots[0][3]; diff --git a/src/Traits/ModelTrait.php b/src/Traits/ModelTrait.php index 905b863..2c7dea8 100644 --- a/src/Traits/ModelTrait.php +++ b/src/Traits/ModelTrait.php @@ -48,7 +48,7 @@ public function with($with, bool $overwrite = false) * Blocks specified tables from being loaded as relations with the next finder. * Used mostly to prevent nesting loops. * - * @param string|string[] $tables Table name or array of table names + * @param list|string $tables Table name or array of table names * * @return $this */ @@ -143,9 +143,9 @@ public function join(...$params) return $this; } - //-------------------------------------------------------------------- + // -------------------------------------------------------------------- // FINDERS EXTENSIONS - //-------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Fetches the row of database from $this->table with a primary key @@ -170,21 +170,21 @@ public function find($id = null) return $this->addRelations($data); } - //-------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Works with the current Query Builder instance to return * all results, while optionally limiting them. * * @return array|null */ - public function findAll(int $limit = null, int $offset = 0) + public function findAll(?int $limit = null, int $offset = 0) { $data = parent::findAll($limit, $offset); return $this->addRelations($data); } - //-------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Returns the first row of the result set. Will take any previous @@ -206,8 +206,6 @@ public function first() * Intercepts data from a finder and injects related items * * @param array $rows Array of rows from the finder - * - * @return array */ protected function addRelations($rows): ?array { diff --git a/tests/entity/RelationsTest.php b/tests/entity/RelationsTest.php index f041db6..3410e96 100644 --- a/tests/entity/RelationsTest.php +++ b/tests/entity/RelationsTest.php @@ -117,7 +117,7 @@ public function testWithDeletedRelations() $machine1 = new Machine((array) $object); $this->assertNull($machine1->factory); - $machine2 = new class () extends Machine { + $machine2 = new class () extends Machine { protected array $withDeletedRelations = ['factories']; }; $machine2->fill((array) $object);