Skip to content

Commit 5270afe

Browse files
committed
coding style
1 parent e5311e3 commit 5270afe

15 files changed

+96
-75
lines changed

src/ComponentModel/ArrayAccess.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function offsetGet($name): IComponent
4848
public function offsetExists($name): bool
4949
{
5050
$name = is_int($name) ? (string) $name : $name;
51-
return $this->getComponent($name, false) !== null;
51+
return $this->getComponent($name, throw: false) !== null;
5252
}
5353

5454

@@ -59,7 +59,7 @@ public function offsetExists($name): bool
5959
public function offsetUnset($name): void
6060
{
6161
$name = is_int($name) ? (string) $name : $name;
62-
if ($component = $this->getComponent($name, false)) {
62+
if ($component = $this->getComponent($name, throw: false)) {
6363
$this->removeComponent($component);
6464
}
6565
}

src/ComponentModel/Component.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ final public function monitor(string $type, ?callable $attached = null, ?callabl
101101
}
102102

103103
if (
104-
($obj = $this->lookup($type, false))
104+
($obj = $this->lookup($type, throw: false))
105105
&& $attached
106-
&& !in_array([$attached, $detached], $this->monitors[$type][3], true)
106+
&& !in_array([$attached, $detached], $this->monitors[$type][3], strict: true)
107107
) {
108108
$attached($obj);
109109
}
@@ -252,7 +252,7 @@ private function refreshMonitors(int $depth, ?array &$missing = null, array &$li
252252

253253
} else {
254254
unset($this->monitors[$type]); // forces re-lookup
255-
if ($obj = $this->lookup($type, false)) {
255+
if ($obj = $this->lookup($type, throw: false)) {
256256
foreach ($rec[3] as $pair) {
257257
$listeners[] = [$pair[0], $obj];
258258
}
@@ -268,7 +268,7 @@ private function refreshMonitors(int $depth, ?array &$missing = null, array &$li
268268
if ($depth === 0) { // call listeners
269269
$prev = [];
270270
foreach ($listeners as $item) {
271-
if ($item[0] && !in_array($item, $prev, true)) {
271+
if ($item[0] && !in_array($item, $prev, strict: true)) {
272272
$item[0]($item[1]);
273273
$prev[] = $item;
274274
}

src/ComponentModel/Container.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ final public function getComponent(string $name, bool $throw = true): ?IComponen
145145
} elseif ($throw) {
146146
$hint = Nette\Utils\ObjectHelpers::getSuggestion(array_merge(
147147
array_map('strval', array_keys($this->components)),
148-
array_map('lcfirst', preg_filter('#^createComponent([A-Z0-9].*)#', '$1', get_class_methods($this)))
148+
array_map('lcfirst', preg_filter('#^createComponent([A-Z0-9].*)#', '$1', get_class_methods($this))),
149149
), $name);
150150
throw new Nette\InvalidArgumentException("Component with name '$name' does not exist" . ($hint ? ", did you mean '$hint'?" : '.'));
151151
}
@@ -191,9 +191,7 @@ final public function getComponents(bool $deep = false, ?string $filterType = nu
191191
}
192192

193193
if ($filterType) {
194-
$iterator = new \CallbackFilterIterator($iterator, function ($item) use ($filterType) {
195-
return $item instanceof $filterType;
196-
});
194+
$iterator = new \CallbackFilterIterator($iterator, fn($item) => $item instanceof $filterType);
197195
}
198196

199197
return $iterator;

tests/ComponentModel/Container.attached.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class TestClass extends Container implements ArrayAccess
2020

2121
public function attached(IComponent $obj): void
2222
{
23-
Notes::add(static::class . '::ATTACHED(' . get_class($obj) . ')');
23+
Notes::add(static::class . '::ATTACHED(' . $obj::class . ')');
2424
}
2525

2626

2727
public function detached(IComponent $obj): void
2828
{
29-
Notes::add(static::class . '::detached(' . get_class($obj) . ')');
29+
Notes::add(static::class . '::detached(' . $obj::class . ')');
3030
}
3131
}
3232

tests/ComponentModel/Container.clone-new.phpt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ class TestClass extends Container implements ArrayAccess
2121

2222
public function attached(IComponent $obj): void
2323
{
24-
Notes::add(static::class . '::ATTACHED(' . get_class($obj) . ')');
24+
Notes::add(static::class . '::ATTACHED(' . $obj::class . ')');
2525
}
2626

2727

2828
public function detached(IComponent $obj): void
2929
{
30-
Notes::add(static::class . '::detached(' . get_class($obj) . ')');
30+
Notes::add(static::class . '::detached(' . $obj::class . ')');
3131
}
3232
}
3333

3434

3535
function export($obj)
3636
{
37-
$res = ['(' . get_class($obj) . ')' => $obj->getName()];
37+
$res = ['(' . $obj::class . ')' => $obj->getName()];
3838
if ($obj instanceof IContainer) {
3939
foreach ($obj->getComponents() as $name => $child) {
4040
$res['children'][$name] = export($child);
@@ -64,9 +64,7 @@ class E extends TestClass
6464

6565
function handler(IComponent $sender, string $label): Closure
6666
{
67-
return function (IComponent $obj) use ($sender, $label) {
68-
Notes::add($label . '(' . get_class($obj) . ', ' . get_class($sender) . ')');
69-
};
67+
return fn(IComponent $obj) => Notes::add($label . '(' . $obj::class . ', ' . $sender::class . ')');
7068
}
7169

7270

@@ -94,7 +92,7 @@ Assert::same([
9492
'detached(A, C)',
9593
], Notes::fetch());
9694

97-
Assert::null($dolly['d']['e']->lookupPath(A::class, false));
95+
Assert::null($dolly['d']['e']->lookupPath(A::class, throw: false));
9896

9997
Assert::same('d-e', $dolly['d']['e']->lookupPath(C::class));
10098

tests/ComponentModel/Container.clone.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ class TestClass extends Container implements ArrayAccess
2121

2222
public function attached(IComponent $obj): void
2323
{
24-
Notes::add(static::class . '::ATTACHED(' . get_class($obj) . ')');
24+
Notes::add(static::class . '::ATTACHED(' . $obj::class . ')');
2525
}
2626

2727

2828
public function detached(IComponent $obj): void
2929
{
30-
Notes::add(static::class . '::detached(' . get_class($obj) . ')');
30+
Notes::add(static::class . '::detached(' . $obj::class . ')');
3131
}
3232
}
3333

3434

3535
function export($obj)
3636
{
37-
$res = ['(' . get_class($obj) . ')' => $obj->getName()];
37+
$res = ['(' . $obj::class . ')' => $obj->getName()];
3838
if ($obj instanceof IContainer) {
3939
foreach ($obj->getComponents() as $name => $child) {
4040
$res['children'][$name] = export($child);
@@ -86,7 +86,7 @@ Assert::same([
8686
'C::detached(A)',
8787
], Notes::fetch());
8888

89-
Assert::null($dolly['d']['e']->lookupPath(A::class, false));
89+
Assert::null($dolly['d']['e']->lookupPath(A::class, throw: false));
9090

9191
Assert::same('d-e', $dolly['d']['e']->lookupPath(C::class));
9292

tests/ComponentModel/Container.commonFactory.error.parent.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class TestClass extends Container
2626
$a = new TestClass;
2727
$a->addComponent(new TestClass, 'a');
2828

29-
Assert::exception(function () use ($a) {
30-
$a->getComponent('b');
31-
}, Nette\InvalidStateException::class, "Component 'a' already has a parent.");
29+
Assert::exception(
30+
fn() => $a->getComponent('b'),
31+
Nette\InvalidStateException::class,
32+
"Component 'a' already has a parent.",
33+
);

tests/ComponentModel/Container.commonFactory.error.type.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TestClass extends Container
2626
$a = new TestClass;
2727
$a->addComponent(new TestClass, 'a');
2828

29-
Assert::exception(function () use ($a) {
30-
$a->getComponent('b');
31-
}, TypeError::class);
29+
Assert::exception(
30+
fn() => $a->getComponent('b'),
31+
TypeError::class,
32+
);

tests/ComponentModel/Container.factory.addComponent.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ $a = new TestClass;
2626
Assert::same('b', $a->getComponent('b')->getName());
2727

2828

29-
Assert::exception(function () use ($a) {
30-
$a->getComponent('B')->getName();
31-
}, InvalidArgumentException::class, "Component with name 'B' does not exist, did you mean 'b'?");
29+
Assert::exception(
30+
fn() => $a->getComponent('B')->getName(),
31+
InvalidArgumentException::class,
32+
"Component with name 'B' does not exist, did you mean 'b'?",
33+
);

tests/ComponentModel/Container.factory.addComponentWithreturn.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ $a = new TestClass;
2727
Assert::same('b', $a->getComponent('b')->getName());
2828

2929

30-
Assert::exception(function () use ($a) {
31-
$a->getComponent('B')->getName();
32-
}, InvalidArgumentException::class, "Component with name 'B' does not exist, did you mean 'b'?");
30+
Assert::exception(
31+
fn() => $a->getComponent('B')->getName(),
32+
InvalidArgumentException::class,
33+
"Component with name 'B' does not exist, did you mean 'b'?",
34+
);

0 commit comments

Comments
 (0)