Skip to content

Commit

Permalink
Bump up phpstan level
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jan 27, 2025
1 parent 52ef250 commit beb7da0
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:

cs-stan:
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
secrets: inherit
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 6
level: 8
paths:
- src
excludePaths:
Expand Down
1 change: 1 addition & 0 deletions src/Action/AddAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected function _post(): ?Response
}

$saveCallback = [$this->_model(), $subject->saveMethod];
/** @phpstan-ignore argument.type */
if (call_user_func($saveCallback, $subject->entity, $subject->saveOptions)) {
return $this->_success($subject);
}
Expand Down
1 change: 1 addition & 0 deletions src/Action/EditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ protected function _put(string|int|null $id = null): ?Response
);

$this->_trigger('beforeSave', $subject);
/** @phpstan-ignore argument.type */
if (call_user_func([$this->_model(), $this->saveMethod()], $entity, $this->saveOptions())) {
return $this->_success($subject);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/Component/CrudComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,10 @@ public function defaults(string $type, array|string $name, mixed $config = null)
return null;
}

/** @psalm-suppress PossiblyInvalidArgument */
/**
* @psalm-suppress PossiblyInvalidArgument
* @phpstan-ignore argument.type
*/
return $this->getConfig(sprintf('%s.%s', $type, $name));
}

Expand Down Expand Up @@ -690,6 +693,7 @@ public function getSubject(array $additional = []): Subject
*/
protected function _loadListeners(): void
{
/** @var string $name */
foreach (array_keys($this->getConfig('listeners')) as $name) {
$this->_loadListener($name);
}
Expand Down
1 change: 1 addition & 0 deletions src/Controller/ControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* For full copyright and license information, please see the LICENSE.txt
*
* @property \Crud\Controller\Component\CrudComponent $Crud
* @phpstan-ignore trait.unused
*/
trait ControllerTrait
{
Expand Down
12 changes: 10 additions & 2 deletions src/Error/ExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ protected function _getQueryLog(): array
$queryLog = [];
$sources = ConnectionManager::configured();
foreach ($sources as $source) {
$logger = ConnectionManager::get($source)->getDriver()->getLogger();
if ($logger && method_exists($logger, 'getLogs')) {
$driver = ConnectionManager::get($source)->getDriver();
if (!method_exists($driver, 'getLogger')) {
continue;
}

$logger = $driver->getLogger();
if (method_exists($logger, 'getLogs')) {
/**
* @var \Crud\Log\QueryLogger $logger
*/
$queryLog[$source] = $logger->getLogs();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Listener/ApiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ protected function _ensureData(Subject $subject): void
}

if (method_exists($subject->entity, $valuePath)) {
/** @phpstan-ignore argument.type */
$data = Hash::insert($data, $keyPath, call_user_func([$subject->entity, $valuePath]));
} elseif (isset($subject->entity->{$valuePath})) {
$data = Hash::insert($data, $keyPath, $subject->entity->{$valuePath});
Expand Down
17 changes: 14 additions & 3 deletions src/Listener/ApiQueryLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Cake\Datasource\Exception\MissingDatasourceConfigException;
use Cake\Event\EventInterface;
use Crud\Log\QueryLogger;
use Psr\Log\LoggerAwareInterface;

/**
* When loaded Crud API will include query logs in the response
Expand Down Expand Up @@ -64,8 +65,10 @@ public function setupLogging(EventInterface $event): void

foreach ($connections as $connectionName) {
try {
$connection = $this->_getSource($connectionName);
$connection->getDriver()->setLogger(new QueryLogger());
$driver = $this->_getSource($connectionName)->getDriver();
if ($driver instanceof LoggerAwareInterface) {
$driver->setLogger(new QueryLogger());
}
} catch (MissingDatasourceConfigException $e) {
//Safe to ignore this :-)
}
Expand Down Expand Up @@ -99,8 +102,16 @@ protected function _getQueryLogs(): array

$queryLog = [];
foreach ($sources as $source) {
$logger = $this->_getSource($source)->getDriver()->getLogger();
$driver = $this->_getSource($source)->getDriver();
if (!method_exists($driver, 'getLogger')) {
continue;
}

$logger = $driver->getLogger();
if (method_exists($logger, 'getLogs')) {
/**
* @var \Crud\Log\QueryLogger $logger
*/
$queryLog[$source] = $logger->getLogs();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Traits/FindMethodTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected function _findRecord(string|int|null $id, Subject $subject): EntityInt
/**
* @psalm-suppress PossiblyInvalidArgument
* @psalm-suppress InvalidArrayOffset
* @phpstan-ignore argument.type
*/
$query->where([current($query->aliasField($repository->getPrimaryKey())) => $id]);

Expand Down

0 comments on commit beb7da0

Please sign in to comment.