From 5a50c88cc46cf00989a5c9b20ec6dc82a878b7f5 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Mon, 4 Dec 2023 19:32:47 +1000 Subject: [PATCH] Update psalm, fix some reported issues and update baseline Signed-off-by: Aleksei Khudiakov --- .gitignore | 1 + composer.json | 2 +- composer.lock | 2 +- psalm-baseline.xml | 737 ++++++++++++++++++------------- psalm.xml.dist | 8 +- src/Listener/ToolbarListener.php | 1 + src/Profiler.php | 5 +- 7 files changed, 445 insertions(+), 311 deletions(-) diff --git a/.gitignore b/.gitignore index 0476ac7..1cb213d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.phpcs-cache /.phpunit.result.cache +/.psalm-cache /clover.xml /coveralls-upload.json /phpunit.xml diff --git a/composer.json b/composer.json index f176c33..6306eae 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "laminas/laminas-coding-standard": "~2.5.0", "phpunit/phpunit": "^9.5.26", "psalm/plugin-phpunit": "^0.18.4", - "vimeo/psalm": "^5.1" + "vimeo/psalm": "^5.16" }, "suggest": { "aist/aist-git-tools": "Show you information about current GIT repository", diff --git a/composer.lock b/composer.lock index f146418..08a56a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5620e9f7446427a33d0c37ecc19eba4f", + "content-hash": "8a483fe7012f03f2664a0b5fbb7771db", "packages": [ { "name": "brick/varexporter", diff --git a/psalm-baseline.xml b/psalm-baseline.xml index aa7f6ae..988b6a6 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,124 +1,137 @@ - + - + $data $data $data $data $data - - $this->data + + data]]> - + collect - - ! $application = $mvcEvent->getApplication() + + getApplication()]]> - + collect - - $serviceLocator->get('ApplicationConfig') - $serviceLocator->get('config') + + get('ApplicationConfig')]]> + get('config')]]> - - $data['applicationConfig'] - $data['config'] + + + - + $serializable[$key] $serializable[$key] $serializable[$key] - + $data $key $serializable[$key] - $this->applicationConfig - $this->config + applicationConfig]]> + config]]> $unserialized[$key] $value $value - + getName getPriority - + static::NAME static::PRIORITY - + $value + + getApplicationConfig + getConfig + - - count($this->profiler->getQueryProfiles($mode)) + + profiler->getQueryProfiles($mode))]]> - + self - + $profiler - + collect - - $this->profiler->getQueryProfiles($mode) + + profiler->getQueryProfiles($mode)]]> - + $query - $this->profiler + profiler]]> $time - + float|integer self - + getElapsedTime - - $query->getElapsedTime() + + getElapsedTime()]]> - + $time - - isset($this->profiler) + + getProfiler + getQueryTime + hasProfiler + setProfiler + + + $profiler + + + profiler)]]> - + Profiler - - $this->profiler - $this->profiler + + profiler]]> + profiler]]> Profiler Profiler - + collectEvent - + collect - - $mvcEvent->getParam('exception') + + getParam('exception')]]> - + SerializableException SerializableException array @@ -130,7 +143,7 @@ string string - + getCode getCode getFile @@ -146,97 +159,118 @@ getTrace getTrace - - $this->data['exception'] - $this->data['exception']->getCode() - $this->data['exception']->getFile() - $this->data['exception']->getMessage() - $this->data['exception']->getPrevious() - $this->data['exception']->getPrevious()->getCode() - $this->data['exception']->getPrevious()->getFile() - $this->data['exception']->getPrevious()->getMessage() - $this->data['exception']->getPrevious()->getTrace() - $this->data['exception']->getTrace() + + data['exception']]]> + data['exception']->getCode()]]> + data['exception']->getFile()]]> + data['exception']->getMessage()]]> + data['exception']->getPrevious()]]> + data['exception']->getPrevious()->getCode()]]> + data['exception']->getPrevious()->getFile()]]> + data['exception']->getPrevious()->getMessage()]]> + data['exception']->getPrevious()->getTrace()]]> + data['exception']->getTrace()]]> + + getCode + getException + getFile + getMessage + getPreviousCode + getPreviousException + getPreviousFile + getPreviousMessage + getPreviousTrace + getTrace + hasException + hasPreviousException + - + collect + + getMailsSend + - - isset($this->data['event']) + + data['event'])]]> - + integer - + collect collectEvent - + $app $app - - $context['memory'] - $context['memory'] - $previous['memory'] + + + + - - $result[$name]['difference'] - $this->data['event'][$id] - $this->data['event'][$id] + + + data['event'][$id]]]> + data['event'][$id]]]> - + $result[$name] $result[$name] - + $app $context $name $previous $result[$name] - $result[$name]['difference'] + - + integer - - $context['memory'] + + - - $this->data['memory'] + + data['memory']]]> - + $context - - isset($this->data) + + getApplicationEventMemory + hasEventMemory + + + data)]]> - + addChildrenToView collect - + $child $controller $controller - $this->data['action'] + data['action']]]> - + $views[] - + $child $controller $var - + array string string @@ -245,132 +279,153 @@ string string - - $this->data['action'] - $this->data['controller'] - $this->data['method'] - $this->data['other_route_parameters'] - $this->data['route'] - $this->data['status'] - $this->data['views'] + + data['action']]]> + data['controller']]]> + data['method']]]> + data['other_route_parameters']]]> + data['route']]]> + data['status']]]> + data['views']]]> - + + getActionName + getControllerName + getFullControllerName + getMethod + getOtherParameters + getRouteName + getStatusCode + getViews + + getMethod getStatusCode - + collect collectEvent - + $app $app - - $context['time'] - $context['time'] - $previous['time'] + + + + - - $result[$index]['elapsed'] - $this->data['event'][$id] - $this->data['event'][$id] + + + data['event'][$id]]]> + data['event'][$id]]]> - + $result[$index] $result[$index] - + $app $context $index $previous $result[$index] - $result[$index]['elapsed'] + - + float float float - + get get - - $context['time'] - $context['time'] - $this->data['end'] + + + + data['end']]]> - - $mvcEvent->getRequest()->getServer()->get('REQUEST_TIME') - $mvcEvent->getRequest()->getServer()->get('REQUEST_TIME_FLOAT') - $this->data['end'] - $this->data['start'] - $this->data['start'] + + getRequest()->getServer()->get('REQUEST_TIME')]]> + getRequest()->getServer()->get('REQUEST_TIME_FLOAT')]]> + data['end'] - $this->data['start']]]> + data['start']]]> REQUEST_MICROTIME - + $context - - isset($this->data) + + getApplicationEventTimes + getExecutionTime + getStartTime + hasEventTimes + + + data)]]> - + getServer getServer + + + IndexController + + - - ! $this->event - $this->event + + event]]> + event]]> - - '' + + - - $backtrace[4]['file'] - $backtrace[4]['file'] - $backtrace[4]['file'] + + + + - - $backtrace[4]['file'] - $backtrace[4]['file'] - $backtrace[4]['file'] - - + integer - - $backtrace[4]['line'] + + - + $event + + + ParameterMissingException + + - - $entry['args'] - $entry['class'] - $this->data['trace'] + + + + data['trace']]]> - - $entry['args'] - $entry['class'] - $entry['class'] - $entry['file'] - $entry['function'] - $entry['line'] - $entry['type'] + + + + + + + + - + $entry - $this->data + data]]> $value - + array integer integer|string @@ -378,104 +433,129 @@ string string - - $this->data['code'] - $this->data['file'] - $this->data['line'] - $this->data['message'] - $this->data['previous'] - $this->data['trace'] + + data['code']]]> + data['file']]]> + data['line']]]> + data['message']]]> + data['previous']]]> + data['trace']]]> + + getCode + getFile + getLine + getPrevious + getTrace + getTraceAsString + - - - static fn(CollectorInterface $collector) => $collector + + $collector, + $collectors + )]]> + + + $collector]]> - + + attachShared + detachShared + + + $events + + (string) $identifier - + onCollected + + $event + + + FirePhpListener + - + onFinish - + onFinish - + $collector - + $collector $profiler $report - + addCollector addError collect setErrorMode - + $name - + onCollected + + $event + + + $serviceLocator + - + $cache[0] - + getModules injectToolbar onCollected - + $content - $content - $content - $content - $content - $headers->get('Content-Type')->getFieldValue() - $moduleManager->getLoadedModules() + get('Content-Type')->getFieldValue()]]> + getLoadedModules()]]> $template $template - $toolbar - + $name - + $content $entries[] $entries[] $entries[] $errors[$name] $headers - $injected $moduleManager $script $style $template $template - $toolbar - + array - + get getFieldValue getLoadedModules @@ -487,8 +567,7 @@ render render - - $content + $script $script $script @@ -496,25 +575,33 @@ $style $style - - $this->listeners + + listeners]]> - + attach getRequest getResponse - + + getLatestVersion + + Version - + getBody getHeaders isXmlHttpRequest + + + MatchInterface + + - + $sm $sm $sm @@ -524,38 +611,38 @@ $sm $sm - + static function ($sm) { - + onLoadModulesPost - + $config - $config->getEventCollectors() - $config->getEventIdentifiers() - $report->getErrors() - $report->getErrors() + getEventCollectors()]]> + getEventIdentifiers()]]> + getErrors()]]> + getErrors()]]> $sm $sm - $sm->get('Application') - $sm->get('Laminas\DeveloperTools\Config') - $sm->get('Laminas\DeveloperTools\Config') - $sm->get('Laminas\DeveloperTools\Event') - $sm->get('ViewRenderer') - $sm->get(Report::class) - $sm->get(Report::class) - $sm->get(Report::class) + get('Application')]]> + get('Laminas\DeveloperTools\Config')]]> + get('Laminas\DeveloperTools\Config')]]> + get('Laminas\DeveloperTools\Event')]]> + get('ViewRenderer')]]> + get(Report::class)]]> + get(Report::class)]]> + get(Report::class)]]> - - array_map([$sm, 'get'], $config->getEventCollectors()) + + getEventCollectors())]]> - - $config['laminas-developer-tools'] - $configuration['laminas-developer-tools']['profiler'] - $configuration['laminas-developer-tools']['profiler']['enabled'] + + + + - + $adapter $app $config @@ -573,7 +660,7 @@ $sm $toolbarListener - + attach attach attach @@ -616,29 +703,29 @@ isToolbarEnabled trigger - + $event - + getEventManager - + getEventManager - + ProfilingAdapter - + getApplication getConfigListener - + is_array($options) is_array($options) - + setCollectors setEventCollectors setEventIdentifiers @@ -647,30 +734,30 @@ setProfiler setToolbar - - $options['collectors'] - $options['identifiers'] + + + $value $value $value - - $this->events['collectors'][$name] - $this->events['identifiers'][$name] - $this->profiler['collectors'][$name] - $this->toolbar[$key][$collector] + + events['collectors'][$name]]]> + events['identifiers'][$name]]]> + profiler['collectors'][$name]]]> + toolbar[$key][$collector]]]> - - $this->events['collectors'][$name] - $this->events['identifiers'][$name] - $this->profiler['collectors'][$name] - $this->toolbar[$key][$collector] + + events['collectors'][$name]]]> + events['identifiers'][$name]]]> + profiler['collectors'][$name]]]> + toolbar[$key][$collector]]]> - - $this->toolbar[$key][$collector] - $this->toolbar[$key][$collector] + + toolbar[$key][$collector]]]> + toolbar[$key][$collector]]]> - + $collector $collector $collector @@ -678,7 +765,7 @@ $template $value - + array array array @@ -692,31 +779,43 @@ bool string - - $this->events['collectors'] - $this->events['enabled'] - $this->events['identifiers'] - $this->profiler['cache_dir'] - $this->profiler['collectors'] - $this->profiler['enabled'] - $this->profiler['strict'] - $this->toolbar['auto_hide'] - $this->toolbar['enabled'] - $this->toolbar['entries'] - $this->toolbar['position'] - $this->toolbar['version_check'] + + events['collectors']]]> + events['enabled']]]> + events['identifiers']]]> + profiler['cache_dir']]]> + profiler['collectors']]]> + profiler['enabled']]]> + profiler['strict']]]> + toolbar['auto_hide']]]> + toolbar['enabled']]]> + toolbar['entries']]]> + toolbar['position']]]> + toolbar['version_check']]]> - - $this->toolbar[$key][$collector] + + toolbar[$key][$collector]]]> - + $options - + + canFlushEarly + eventCollectionEnabled + getEventCollectors + getEventIdentifiers + setEvents + setProfiler + + + $options + $report + + is_array($options) is_array($options) - + ConfigCollector DbCollector ExceptionCollector @@ -726,61 +825,64 @@ TimeCollector TimeCollector - + array|Traversable|null - + self - - $collector - $mvcEvent->getRequest()->getMethod() - $mvcEvent->getRequest()->getServer()->get('REMOTE_ADDR') - $mvcEvent->getRequest()->getUriString() + + getRequest()->getMethod()]]> + getRequest()->getServer()->get('REMOTE_ADDR')]]> + getRequest()->getUriString()]]> - - $collector - - - collect + get - + + addCollector + collect + setErrorMode + + $collectors $event $eventManager $strict - + $event - - isset($this->collectors) - isset($this->collectors) - isset($this->event) + + collectors)]]> + collectors)]]> + event)]]> - + getMethod getServer getUriString - + ApplicationInterface|null ReportInterface string - - $this->getParam('application') - $this->getParam('profiler') - $this->getParam('report') + + getParam('application')]]> + getParam('profiler')]]> + getParam('report')]]> + + getProfiler + - + $errors $ip $method @@ -788,41 +890,64 @@ $token $uri - + $collector - + $collector - + getCollector - - $this->collectors[$name] + + collectors[$name]]]> - - isset($this->errors) + + errors)]]> + + + getCollectorNames + getCollectors + getIp + getMethod + getTime + getToken + getUri + hasCollector + setCollectors + + + self + self + self + + + + + StorageInterface + + - + $entry - + $entry - + iDoNotExist - + testOnlyWhitelistedToolbarEntriesShouldBeEnabled - - Generator<non-empty-string, list<scalar>> + + >]]> diff --git a/psalm.xml.dist b/psalm.xml.dist index 655f63e..dde9e6b 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -1,12 +1,16 @@ + diff --git a/src/Listener/ToolbarListener.php b/src/Listener/ToolbarListener.php index 6e6b8e6..0141dec 100644 --- a/src/Listener/ToolbarListener.php +++ b/src/Listener/ToolbarListener.php @@ -115,6 +115,7 @@ protected function injectToolbar(ProfilerEvent $event) $toolbarView = new ViewModel(['entries' => $entries]); $toolbarView->setTemplate('laminas-developer-tools/toolbar/toolbar'); + /** @var string $toolbar */ $toolbar = $this->renderer->render($toolbarView); $toolbarCss = new ViewModel([ diff --git a/src/Profiler.php b/src/Profiler.php index 0af80ff..060d86b 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -6,12 +6,14 @@ use DateTime; use DateTimeZone; +use Laminas\DeveloperTools\Collector\CollectorInterface; use Laminas\EventManager\EventInterface; use Laminas\EventManager\EventManagerAwareInterface; use Laminas\EventManager\EventManagerInterface; use Laminas\Mvc\MvcEvent; use Laminas\Stdlib\PriorityQueue; +use function assert; use function sprintf; use function uniqid; @@ -147,7 +149,7 @@ public function getEventManager() /** * Adds a collector. * - * @param Collector\CollectorInterface $collector + * @param CollectorInterface $collector * @return self * @throws Exception\CollectorException */ @@ -188,6 +190,7 @@ public function collect(MvcEvent $mvcEvent) if (isset($this->collectors)) { foreach ($this->collectors as $collector) { + assert($collector instanceof CollectorInterface); $collector->collect($mvcEvent); $this->report->addCollector($collector); }