Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed May 5, 2022
2 parents 1f9ac67 + 1fe8864 commit 4e905d1
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 81 deletions.
8 changes: 2 additions & 6 deletions src/Build/BuildContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ public function __construct(array $params)

/**
* @param array<string, mixed> $params
*
* @return BuildContext
*/
public function change(array $params)
public function change(array $params): self
{
return new self(array_merge($this->params, $params));
}

/**
* @param string $name
*
* @return mixed|null
*/
public function get($name)
public function get(string $name)
{
return isset($this->params[$name]) ? $this->params[$name] : null;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Build/BuildDirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
*/
interface BuildDirector
{
/**
* @return void
*/
public function build(BuildContext $c, Tree $t, BuildDispatcher $d);
}
12 changes: 6 additions & 6 deletions src/Build/BuildDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class BuildDispatcher
protected $resources = [];
protected $queue;

public function addDirector(BuildDirector $director, $priority = 100)
public function addDirector(BuildDirector $director, $priority = 100): void
{
$this->directors[$priority][] = $director;
}

public function start(Tree $tree)
public function start(Tree $tree): void
{
$directorsOrderedByPriority = $this->getDirectorsOrderedByPriority();
$this->queue = [new BuildContext([])];
Expand All @@ -33,25 +33,25 @@ public function start(Tree $tree)
}
}

public function search(BuildContext $context)
public function search(BuildContext $context): void
{
$this->queue[] = $context;
}

public function addResource(ResourceInterface $resource)
public function addResource(ResourceInterface $resource): void
{
$this->resources[] = $resource;
}

public function getResources()
public function getResources(): array
{
return array_unique($this->resources);
}

/**
* @return BuildDirector[]
*/
private function getDirectorsOrderedByPriority()
private function getDirectorsOrderedByPriority(): array
{
krsort($this->directors, \SORT_NUMERIC);
$buildDirectorsOrderedByPriority = [];
Expand Down
20 changes: 6 additions & 14 deletions src/Build/TreeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TreeFactory implements ServiceSubscriberInterface
/** @var ContainerInterface */
protected $container;

public static function getSubscribedServices()
public static function getSubscribedServices(): array
{
return [
BuildDispatcher::class,
Expand All @@ -64,19 +64,14 @@ public function __construct(
$this->stopwatch = $stopwatch;
}

public function debug($msg)
public function debug(string $msg): void
{
if ($this->logger) {
$this->logger->debug("$msg (PID ".getmypid().', microtime '.microtime().')');
}
}

/**
* @param $sectionName
*
* @return StopwatchEvent|null
*/
protected function startTiming($sectionName)
protected function startTiming(string $sectionName): ?StopwatchEvent
{
if ($this->stopwatch) {
return $this->stopwatch->start('webfactory/navigation-bundle: '.$sectionName);
Expand All @@ -85,17 +80,14 @@ protected function startTiming($sectionName)
return null;
}

protected function stopTiming(StopwatchEvent $watch = null)
protected function stopTiming(StopwatchEvent $watch = null): void
{
if ($watch) {
$watch->stop();
}
}

/**
* @return Tree
*/
public function getTree()
public function getTree(): Tree
{
if (!$this->_tree) {
$self = $this;
Expand Down Expand Up @@ -124,7 +116,7 @@ public function getTree()
return $this->_tree;
}

public function buildTreeCache(ConfigCacheInterface $cache)
public function buildTreeCache(ConfigCacheInterface $cache): void
{
$this->_tree = new Tree();
// Dynamic (runtime) lookup:
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DumpTreeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

private function dumpNode(Node $n, OutputInterface $output, $depth = 0)
private function dumpNode(Node $n, OutputInterface $output, $depth = 0): void
{
$first = true;

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/BuildDirectorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class BuildDirectorPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (false === $container->hasDefinition(BuildDispatcher::class)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/WebfactoryNavigationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class WebfactoryNavigationExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ActiveNodeEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(RequestStack $requestStack)
$this->requestStack = $requestStack;
}

public function initializeTree(TreeInitializedEvent $event)
public function initializeTree(TreeInitializedEvent $event): void
{
if ($masterRequest = $this->requestStack->getMasterRequest()) {
if ($node = $event->getTree()->find($masterRequest->attributes->all())) {
Expand Down
5 changes: 1 addition & 4 deletions src/Event/TreeInitializedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public function __construct(Tree $tree)
$this->tree = $tree;
}

/**
* @return Tree
*/
public function getTree()
public function getTree(): Tree
{
return $this->tree;
}
Expand Down
9 changes: 2 additions & 7 deletions src/Tree/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class Finder
/** @var string[] */
protected $idToHash = [];

/**
* @param Node $object
*/
public function add($object, array $requirements)
public function add(Node $object, array $requirements): void
{
$hash = spl_object_hash($object);
$this->objects[$hash] = $object;
Expand All @@ -47,10 +44,8 @@ public function add($object, array $requirements)

/**
* @param string|array|object $provided
*
* @return Node|null
*/
public function lookup($provided)
public function lookup($provided): ?Node
{
$remainingCount = [];
$maxMatch = 0;
Expand Down
47 changes: 21 additions & 26 deletions src/Tree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Node implements \ArrayAccess
*
* @return Node returns the given or newly created node, for use in fluent notations
*/
public function addChild(self $n = null)
public function addChild(self $n = null): self
{
if (null === $n) {
$n = new self();
Expand All @@ -47,12 +47,12 @@ public function addChild(self $n = null)
return $n;
}

public function setTree(Tree $t)
public function setTree(Tree $t): void
{
$this->tree = $t;
}

public function getTree()
public function getTree(): Tree
{
return $this->tree;
}
Expand All @@ -64,15 +64,15 @@ public function getTree()
*
* @return $this the node itself, for use in fluent notations
*/
public function index(array $requirements)
public function index(array $requirements): self
{
$this->tree->addFindIndex($this, $requirements);

return $this;
}

/** @deprecated */
public function activateOn(array $requirements)
public function activateOn(array $requirements): self
{
return $this->index($requirements);
}
Expand All @@ -85,7 +85,7 @@ public function activateOn(array $requirements)
*
* @return $this the node itself, for use in fluent notations
*/
public function set($name, $value)
public function set($name, $value): self
{
$this->data[$name] = $value;

Expand All @@ -99,33 +99,28 @@ public function set($name, $value)
*
* @return mixed|null the value, or null if the $name is unknown
*/
public function get($name)
public function get(string $name)
{
return isset($this->data[$name]) ? $this->data[$name] : null;
}

/**
* Returns all data stored in this node.
*
* @return array
*/
public function getData()
public function getData(): array
{
return $this->data;
}

/**
* @return Node|null returns the parent node
*/
public function getParent()
public function getParent(): ?self
{
return $this->parent;
}

/**
* @return Node[] the array of all Nodes from the root towards this node
*/
public function getPath()
public function getPath(): array
{
if (null === $this->parent) {
return [$this];
Expand All @@ -140,23 +135,23 @@ public function getPath()
/**
* @return Node[] returns all child nodes
*/
public function getChildren()
public function getChildren(): array
{
return $this->children;
}

/**
* @return bool whether the node has child nodes or not
*/
public function hasChildren()
public function hasChildren(): bool
{
return (bool) $this->children;
}

/**
* @return bool whether the node has visible child nodes or not
*/
public function hasVisibleChildren()
public function hasVisibleChildren(): bool
{
foreach ($this->children as $childNode) {
if (true === $childNode->get('visible')) {
Expand All @@ -172,7 +167,7 @@ public function hasVisibleChildren()
*
* @return bool true if the given node is an ancestor of the current node
*/
public function hasAncestor(self $ancestor)
public function hasAncestor(self $ancestor): bool
{
return $this->parent && (($this->parent === $ancestor) || $this->parent->hasAncestor($ancestor));
}
Expand All @@ -182,15 +177,15 @@ public function hasAncestor(self $ancestor)
*
* @return bool true if $descendant is a descendant of the current node
*/
public function hasDescendant(self $descendant)
public function hasDescendant(self $descendant): bool
{
return $descendant->hasAncestor($this);
}

/**
* @return int returns the level of this node, with "0" being the root level
*/
public function getLevel()
public function getLevel(): int
{
if ($this->parent) {
return $this->parent->getLevel() + 1;
Expand All @@ -204,7 +199,7 @@ public function getLevel()
*
* @return $this the node itself, for use in fluent notations
*/
public function setActive()
public function setActive(): self
{
$this->tree->setActiveNode($this);

Expand All @@ -225,7 +220,7 @@ public function setActive()
*
* @return $this the node itself, for use in fluent notations
*/
public function setActivePath()
public function setActivePath(): self
{
$this->tree->setActivePath($this);

Expand All @@ -235,15 +230,15 @@ public function setActivePath()
/**
* @return bool whether this is the currently active node in the tree
*/
public function isActiveNode()
public function isActiveNode(): bool
{
return $this->tree->getActiveNode() === $this;
}

/**
* @return bool whether this node lies on the path from the Tree root towards the active node
*/
public function isActivePath()
public function isActivePath(): bool
{
if (!($ap = $this->tree->getActivePath())) {
return false;
Expand Down Expand Up @@ -288,7 +283,7 @@ public function offsetUnset($offset): void
unset($this->data[$offset]);
}

protected function setParent(self $p)
protected function setParent(self $p): void
{
$this->parent = $p;
}
Expand Down
Loading

0 comments on commit 4e905d1

Please sign in to comment.