Skip to content

Commit

Permalink
Merge pull request #60 from samsonasik/apply-php80
Browse files Browse the repository at this point in the history
Apply PHP 8.0 Syntax and constructor promotion
  • Loading branch information
samsonasik authored Dec 10, 2022
2 parents c2bd090 + 1ce19fe commit 2e3d39e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
7 changes: 3 additions & 4 deletions src/Collector/RequestCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use function array_filter;
use function array_pop;
use function explode;
use function gettype;
use function get_debug_type;
use function in_array;
use function is_object;
use function sort;
use function sprintf;

Expand Down Expand Up @@ -58,7 +57,7 @@ public function collect(MvcEvent $mvcEvent)
$vars = (array) $vars;

foreach ($vars as $key => &$var) {
$var = $key . ': ' . (is_object($var) ? $var::class : gettype($var));
$var = $key . ': ' . get_debug_type($var);
}
sort($vars);

Expand All @@ -80,7 +79,7 @@ public function collect(MvcEvent $mvcEvent)
'controller' => $match === null ? 'N/A' : $match->getParam('controller', 'N/A'),
'other_route_parameters' => $match === null ? 'N/A' : array_filter(
$match->getParams(),
static fn($key) => ! in_array($key, ['action', 'controller']),
static fn($key): bool => ! 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 @@ -83,10 +83,9 @@ public function getEventTarget()
/**
* Determines a string label to represent an event target.
*
* @param mixed $target
* @return string
*/
private function getEventTargetAsString($target)
private function getEventTargetAsString(mixed $target)
{
if (is_object($target)) {
return $target::class;
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/EventLoggingListenerAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(array $collectors, array $identifiers)
$collectors
);
$this->identifiers = array_values(array_map(
static fn($identifier) => (string) $identifier,
static fn($identifier): string => (string) $identifier,
$identifiers
));
}
Expand Down
16 changes: 6 additions & 10 deletions src/Listener/ToolbarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
use function preg_match;
use function preg_replace;
use function sprintf;
use function str_contains;
use function str_replace;
use function stripos;
use function strpos;
use function time;

/**
Expand All @@ -53,19 +53,15 @@ class ToolbarListener implements ListenerAggregateInterface
*/
public const DOC_URI = 'https://docs.laminas.dev/';

/** @var object */
protected $renderer;

/** @var Options */
protected $options;

/**
* @param object $viewRenderer
* @param object $renderer
*/
public function __construct($viewRenderer, Options $options)
public function __construct(protected $renderer, Options $options)
{
$this->options = $options;
$this->renderer = $viewRenderer;
$this->options = $options;
}

/**
Expand Down Expand Up @@ -97,7 +93,7 @@ public function onCollected(ProfilerEvent $event)
$headers = $response->getHeaders();
if (
$headers->has('Content-Type')
&& false === strpos($headers->get('Content-Type')->getFieldValue(), 'html')
&& ! str_contains($headers->get('Content-Type')->getFieldValue(), 'html')
) {
return;
}
Expand Down Expand Up @@ -204,7 +200,7 @@ protected function renderEntries(ProfilerEvent $event)
]);
$collector->setTemplate($template);
$entries[] = $this->renderer->render($collector);
} catch (RuntimeException $e) {
} catch (RuntimeException) {
$errors[$name] = $template;
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use BjyProfiler\Db\Adapter\ProfilingAdapter;
use Laminas\DeveloperTools\Collector\DbCollector;
use Laminas\DeveloperTools\Listener\EventLoggingListenerAggregate;
use Laminas\DeveloperTools\Listener\ProfilerListener;
use Laminas\DeveloperTools\Listener\StorageListener;
use Laminas\DeveloperTools\Listener\ToolbarListener;
use Laminas\DeveloperTools\Options;
use Laminas\DeveloperTools\Profiler;
use Laminas\DeveloperTools\ProfilerEvent;
Expand Down Expand Up @@ -110,11 +113,11 @@ public function onBootstrap(EventInterface $event)
$eventLoggingListener->attachShared($sem);
}

$profilerListener = $sm->get(Listener\ProfilerListener::class);
$profilerListener = $sm->get(ProfilerListener::class);
$profilerListener->attach($em);

if ($options->isToolbarEnabled()) {
$toolbarListener = $sm->get(Listener\ToolbarListener::class);
$toolbarListener = $sm->get(ToolbarListener::class);
$toolbarListener->attach($em);
}

Expand Down Expand Up @@ -175,8 +178,8 @@ public function getServiceConfig()
'ZendDeveloperTools\Config' => 'Laminas\DeveloperTools\Config',
'ZendDeveloperTools\Event' => 'Laminas\DeveloperTools\Event',
'ZendDeveloperTools\StorageListener' => 'Laminas\DeveloperTools\StorageListener',
'ZendDeveloperTools\Listener\ToolbarListener' => Listener\ToolbarListener::class,
'ZendDeveloperTools\Listener\ProfilerListener' => Listener\ProfilerListener::class,
'ZendDeveloperTools\Listener\ToolbarListener' => ToolbarListener::class,
'ZendDeveloperTools\Listener\ProfilerListener' => ProfilerListener::class,
'ZendDeveloperTools\Listener\EventLoggingListenerAggregate' => EventLoggingListenerAggregate::class,
'ZendDeveloperTools\DbCollector' => 'Laminas\DeveloperTools\DbCollector',
/** phpcs:enable Generic.Files.LineLength */
Expand Down Expand Up @@ -208,12 +211,12 @@ public function getServiceConfig()
$event->setApplication($sm->get('Application'));
return $event;
},
'Laminas\DeveloperTools\StorageListener' => static fn($sm) => new Listener\StorageListener($sm),
Listener\ToolbarListener::class => static fn($sm) => new Listener\ToolbarListener(
'Laminas\DeveloperTools\StorageListener' => static fn($sm): StorageListener => new StorageListener($sm),
ToolbarListener::class => static fn($sm): ToolbarListener => new ToolbarListener(
$sm->get('ViewRenderer'),
$sm->get('Laminas\DeveloperTools\Config')
),
Listener\ProfilerListener::class => static fn($sm) => new Listener\ProfilerListener(
ProfilerListener::class => static fn($sm): ProfilerListener => new ProfilerListener(
$sm,
$sm->get('Laminas\DeveloperTools\Config')
),
Expand Down
10 changes: 0 additions & 10 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public function __construct($options, ReportInterface $report)

/**
* Sets Profiler options.
*
* @param array $options
*/
public function setProfiler(array $options)
{
Expand Down Expand Up @@ -112,8 +110,6 @@ public function setProfiler(array $options)

/**
* Sets Event-level profiling options.
*
* @param array $options
*/
public function setEvents(array $options)
{
Expand Down Expand Up @@ -185,8 +181,6 @@ public function isEnabled()

/**
* Sets Event-level collectors.
*
* @param array $options
*/
public function setEventCollectors(array $options)
{
Expand All @@ -211,8 +205,6 @@ public function setEventCollectors(array $options)
/**
* Set Event-level collectors to listen to certain event identifiers. Defaults to '*' which causes the listener to
* attach to all events.
*
* @param array $options
*/
public function setEventIdentifiers(array $options)
{
Expand Down Expand Up @@ -314,8 +306,6 @@ public function getEventIdentifiers()

/**
* Sets Toolbar options.
*
* @param array $options
*/
public function setToolbar(array $options)
{
Expand Down

0 comments on commit 2e3d39e

Please sign in to comment.