Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply PHP 7.4 syntax and typed property #53

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
<code>$sm</code>
</MissingClosureParamType>
<MissingClosureReturnType occurrences="1">
<code>function ($sm) {</code>
<code>static function ($sm) {</code>
</MissingClosureReturnType>
<MissingReturnType occurrences="1">
<code>onLoadModulesPost</code>
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/ConfigCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private function unserializeArray(array $data)
}

if ($value instanceof ClosureStub) {
$unserialized[$key] = function () {
$unserialized[$key] = static function (): void {
};
continue;
}
Expand Down
10 changes: 6 additions & 4 deletions src/Collector/RequestCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function collect(MvcEvent $mvcEvent)
$match = $mvcEvent->getRouteMatch();
$viewModel = $mvcEvent->getViewModel();

$addToViewFromModel = function (ModelInterface $child) use (&$views) {
$addToViewFromModel = static function (ModelInterface $child) use (&$views): void {
$vars = $child->getVariables();

if ($vars instanceof Variables) {
Expand Down Expand Up @@ -79,9 +79,11 @@ public function collect(MvcEvent $mvcEvent)
'route' => $match === null ? 'N/A' : $match->getMatchedRouteName(),
'action' => $match === null ? 'N/A' : $match->getParam('action', 'N/A'),
'controller' => $match === null ? 'N/A' : $match->getParam('controller', 'N/A'),
'other_route_parameters' => $match === null ? 'N/A' : array_filter($match->getParams(), function ($key) {
return ! in_array($key, ['action', 'controller']);
}, ARRAY_FILTER_USE_KEY),
'other_route_parameters' => $match === null ? 'N/A' : array_filter(
$match->getParams(),
static fn($key) => ! in_array($key, ['action', 'controller']),
ARRAY_FILTER_USE_KEY
),
];
}

Expand Down
3 changes: 1 addition & 2 deletions src/EventLogging/EventContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class EventContextProvider implements EventContextInterface
/** @var EventInterface */
protected $event;

/** @var array */
private $debugBacktrace = [];
private array $debugBacktrace = [];

/**
* @param EventInterface|null $event (Optional) The event to provide context to.
Expand Down
8 changes: 2 additions & 6 deletions src/Listener/EventLoggingListenerAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ class EventLoggingListenerAggregate
public function __construct(array $collectors, array $identifiers)
{
$this->collectors = array_map(
function (CollectorInterface $collector) {
return $collector;
},
static fn(CollectorInterface $collector) => $collector,
$collectors
);
$this->identifiers = array_values(array_map(
function ($identifier) {
return (string) $identifier;
},
static fn($identifier) => (string) $identifier,
$identifiers
));
}
Expand Down
8 changes: 5 additions & 3 deletions src/Listener/ToolbarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ protected function injectToolbar(ProfilerEvent $event)
$injected = preg_replace('/<\/' . $prepend . '>/i', $style . "\n</$prepend>", $injected, 1);
} else {
$injected = $isHtml5
? (stripos($content, '</html>') !== false
? preg_replace('/<\/html>/i', $style . $toolbar . $script . "\n</html>", $content, 1)
: '<!doctype html>' . $content . $style . $toolbar . $script)
? (
stripos($content, '</html>') !== false
? preg_replace('/<\/html>/i', $style . $toolbar . $script . "\n</html>", $content, 1)
: '<!doctype html>' . $content . $style . $toolbar . $script
)
: $content;
}

Expand Down
47 changes: 23 additions & 24 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
namespace Laminas\DeveloperTools;

use BjyProfiler\Db\Adapter\ProfilingAdapter;
use Laminas\DeveloperTools\Collector\DbCollector;
use Laminas\DeveloperTools\Listener\EventLoggingListenerAggregate;
use Laminas\DeveloperTools\Options;
use Laminas\DeveloperTools\Profiler;
use Laminas\DeveloperTools\ProfilerEvent;
use Laminas\EventManager\EventInterface;
use Laminas\ModuleManager\Feature\BootstrapListenerInterface;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
Expand Down Expand Up @@ -101,7 +106,7 @@ public function onBootstrap(EventInterface $event)

if ($options->eventCollectionEnabled()) {
$sem = $em->getSharedManager();
$eventLoggingListener = $sm->get(Listener\EventLoggingListenerAggregate::class);
$eventLoggingListener = $sm->get(EventLoggingListenerAggregate::class);
$eventLoggingListener->attachShared($sem);
}

Expand Down Expand Up @@ -172,7 +177,7 @@ public function getServiceConfig()
'ZendDeveloperTools\StorageListener' => 'Laminas\DeveloperTools\StorageListener',
'ZendDeveloperTools\Listener\ToolbarListener' => Listener\ToolbarListener::class,
'ZendDeveloperTools\Listener\ProfilerListener' => Listener\ProfilerListener::class,
'ZendDeveloperTools\Listener\EventLoggingListenerAggregate' => Listener\EventLoggingListenerAggregate::class,
'ZendDeveloperTools\Listener\EventLoggingListenerAggregate' => EventLoggingListenerAggregate::class,
'ZendDeveloperTools\DbCollector' => 'Laminas\DeveloperTools\DbCollector',
/** phpcs:enable Generic.Files.LineLength */
],
Expand All @@ -187,47 +192,41 @@ public function getServiceConfig()
'Laminas\DeveloperTools\FlushListener' => Listener\FlushListener::class,
],
'factories' => [
Profiler::class => function ($sm) {
Profiler::class => static function ($sm): Profiler {
$a = new Profiler($sm->get(Report::class));
$a->setEvent($sm->get('Laminas\DeveloperTools\Event'));
return $a;
},
'Laminas\DeveloperTools\Config' => function ($sm) {
'Laminas\DeveloperTools\Config' => static function ($sm): Options {
$config = $sm->get('Configuration');
$config = $config['laminas-developer-tools'] ?? null;

return new Options($config, $sm->get(Report::class));
},
'Laminas\DeveloperTools\Event' => function ($sm) {
'Laminas\DeveloperTools\Event' => static function ($sm): ProfilerEvent {
$event = new ProfilerEvent();
$event->setReport($sm->get(Report::class));
$event->setApplication($sm->get('Application'));

return $event;
},
'Laminas\DeveloperTools\StorageListener' => function ($sm) {
return new Listener\StorageListener($sm);
},
Listener\ToolbarListener::class => function ($sm) {
return new Listener\ToolbarListener(
$sm->get('ViewRenderer'),
$sm->get('Laminas\DeveloperTools\Config')
);
},
Listener\ProfilerListener::class => function ($sm) {
return new Listener\ProfilerListener($sm, $sm->get('Laminas\DeveloperTools\Config'));
},
Listener\EventLoggingListenerAggregate::class => function ($sm) {
'Laminas\DeveloperTools\StorageListener' => static fn($sm) => new Listener\StorageListener($sm),
Listener\ToolbarListener::class => static fn($sm) => new Listener\ToolbarListener(
$sm->get('ViewRenderer'),
$sm->get('Laminas\DeveloperTools\Config')
),
Listener\ProfilerListener::class => static fn($sm) => new Listener\ProfilerListener(
$sm,
$sm->get('Laminas\DeveloperTools\Config')
),
EventLoggingListenerAggregate::class => static function ($sm): EventLoggingListenerAggregate {
$config = $sm->get('Laminas\DeveloperTools\Config');

return new Listener\EventLoggingListenerAggregate(
return new EventLoggingListenerAggregate(
array_map([$sm, 'get'], $config->getEventCollectors()),
$config->getEventIdentifiers()
);
},
'Laminas\DeveloperTools\DbCollector' => function ($sm) {
'Laminas\DeveloperTools\DbCollector' => static function ($sm) {
$p = false;
$db = new Collector\DbCollector();
$db = new DbCollector();

if ($sm->has('Laminas\Db\Adapter\Adapter') && isset($sm->get('config')['db'])) {
$adapter = $sm->get('Laminas\Db\Adapter\Adapter');
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function __invoke($time, $precision = 2)
return sprintf('%.' . $precision . 'f ms', $time * 1000);
}

return sprintf('%.' . $precision . 'f µs', $time * 1000000);
return sprintf('%.' . $precision . 'f µs', $time * 1_000_000);
}
}