@@ -9,6 +9,6 @@ |
||
9 | 9 | public function __construct( |
10 | 10 | public readonly string $key, |
11 | 11 | public readonly mixed $value, |
12 | - ) { |
|
12 | + ){ |
|
13 | 13 | } |
14 | 14 | } |
@@ -8,6 +8,6 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct( |
10 | 10 | public readonly string $key, |
11 | - ) { |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | } |
@@ -9,6 +9,6 @@ |
||
9 | 9 | public function __construct( |
10 | 10 | public readonly string $key, |
11 | 11 | public readonly mixed $value |
12 | - ) { |
|
12 | + ){ |
|
13 | 13 | } |
14 | 14 | } |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | { |
20 | 20 | public function __construct( |
21 | 21 | private readonly CacheStorageProviderInterface $provider |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
26 | 26 | { |
27 | - try { |
|
28 | - if ($context === null) { |
|
27 | + try{ |
|
28 | + if ($context === null){ |
|
29 | 29 | $connection = $this->provider->storage(); |
30 | - } else { |
|
30 | + }else{ |
|
31 | 31 | // Get Cache by context |
32 | - try { |
|
32 | + try{ |
|
33 | 33 | $connection = $this->provider->storage($context); |
34 | - } catch (InvalidArgumentException) { |
|
34 | + }catch (InvalidArgumentException){ |
|
35 | 35 | // Case when context doesn't match to configured connections |
36 | 36 | return $this->provider->storage(); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | 40 | $this->matchType($class, $context, $connection); |
41 | - } catch (\Throwable $e) { |
|
41 | + }catch (\Throwable $e){ |
|
42 | 42 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
43 | 43 | } |
44 | 44 | |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
54 | 54 | { |
55 | - if ($connection::class === CacheRepository::class) { |
|
55 | + if ($connection::class === CacheRepository::class){ |
|
56 | 56 | $connection = $connection->getStorage(); |
57 | 57 | } |
58 | 58 | $className = $class->getName(); |
59 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
59 | + if ($className !== CacheInterface::class && !$connection instanceof $className){ |
|
60 | 60 | throw new \RuntimeException( |
61 | 61 | \sprintf( |
62 | 62 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -24,21 +24,30 @@ discard block |
||
24 | 24 | |
25 | 25 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
26 | 26 | { |
27 | - try { |
|
28 | - if ($context === null) { |
|
27 | + try |
|
28 | + { |
|
29 | + if ($context === null) |
|
30 | + { |
|
29 | 31 | $connection = $this->provider->storage(); |
30 | - } else { |
|
32 | + } |
|
33 | + else |
|
34 | + { |
|
31 | 35 | // Get Cache by context |
32 | - try { |
|
36 | + try |
|
37 | + { |
|
33 | 38 | $connection = $this->provider->storage($context); |
34 | - } catch (InvalidArgumentException) { |
|
39 | + } |
|
40 | + catch (InvalidArgumentException) |
|
41 | + { |
|
35 | 42 | // Case when context doesn't match to configured connections |
36 | 43 | return $this->provider->storage(); |
37 | 44 | } |
38 | 45 | } |
39 | 46 | |
40 | 47 | $this->matchType($class, $context, $connection); |
41 | - } catch (\Throwable $e) { |
|
48 | + } |
|
49 | + catch (\Throwable $e) |
|
50 | + { |
|
42 | 51 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
43 | 52 | } |
44 | 53 | |
@@ -52,11 +61,13 @@ discard block |
||
52 | 61 | */ |
53 | 62 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
54 | 63 | { |
55 | - if ($connection::class === CacheRepository::class) { |
|
64 | + if ($connection::class === CacheRepository::class) |
|
65 | + { |
|
56 | 66 | $connection = $connection->getStorage(); |
57 | 67 | } |
58 | 68 | $className = $class->getName(); |
59 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
69 | + if ($className !== CacheInterface::class && !$connection instanceof $className) |
|
70 | + { |
|
60 | 71 | throw new \RuntimeException( |
61 | 72 | \sprintf( |
62 | 73 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -21,7 +21,7 @@ |
||
21 | 21 | return new \DateTimeImmutable(); |
22 | 22 | } |
23 | 23 | |
24 | - private function ttlToTimestamp(null|int|\DateInterval|\DateTimeInterface $ttl = null): int |
|
24 | + private function ttlToTimestamp(null | int | \DateInterval | \DateTimeInterface $ttl = null): int |
|
25 | 25 | { |
26 | 26 | return match (true) { |
27 | 27 | $ttl instanceof \DateInterval => $this->now()->add($ttl)->getTimestamp(), |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct( |
19 | 19 | private readonly int $ttl = 2_592_000 |
20 | - ) { |
|
20 | + ){ |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function get(string $key, mixed $default = null): mixed |
24 | 24 | { |
25 | - if (!isset($this->storage[$key])) { |
|
25 | + if (!isset($this->storage[$key])){ |
|
26 | 26 | return $default; |
27 | 27 | } |
28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | $expiresAt = $item['timestamp'] ?? 0; |
32 | 32 | |
33 | - if ($expiresAt !== 0 && \time() >= $expiresAt) { |
|
33 | + if ($expiresAt !== 0 && \time() >= $expiresAt){ |
|
34 | 34 | $this->delete($key); |
35 | 35 | |
36 | 36 | return $default; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | return $item['value']; |
40 | 40 | } |
41 | 41 | |
42 | - public function set(string $key, mixed $value, null|int|\DateInterval|\DateTimeInterface $ttl = null): bool |
|
42 | + public function set(string $key, mixed $value, null | int | \DateInterval | \DateTimeInterface $ttl = null): bool |
|
43 | 43 | { |
44 | 44 | $this->storage[$key] = [ |
45 | 45 | 'value' => $value, |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | public function delete(string $key): bool |
53 | 53 | { |
54 | - if ($this->has($key)) { |
|
54 | + if ($this->has($key)){ |
|
55 | 55 | unset($this->storage[$key]); |
56 | 56 | |
57 | 57 | return true; |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | { |
72 | 72 | $return = []; |
73 | 73 | |
74 | - foreach ($keys as $key) { |
|
74 | + foreach ($keys as $key){ |
|
75 | 75 | $return[$key] = $this->get($key, $default); |
76 | 76 | } |
77 | 77 | |
78 | 78 | return $return; |
79 | 79 | } |
80 | 80 | |
81 | - public function setMultiple(iterable $values, null|int|\DateInterval|\DateTimeInterface $ttl = null): bool |
|
81 | + public function setMultiple(iterable $values, null | int | \DateInterval | \DateTimeInterface $ttl = null): bool |
|
82 | 82 | { |
83 | - foreach ($values as $key => $value) { |
|
83 | + foreach ($values as $key => $value){ |
|
84 | 84 | $this->set($key, $value, $ttl); |
85 | 85 | } |
86 | 86 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | { |
92 | 92 | $state = null; |
93 | 93 | |
94 | - foreach ($keys as $key) { |
|
94 | + foreach ($keys as $key){ |
|
95 | 95 | $result = $this->delete($key); |
96 | 96 | |
97 | 97 | $state = \is_null($state) ? $result : $result && $state; |
@@ -22,7 +22,8 @@ discard block |
||
22 | 22 | |
23 | 23 | public function get(string $key, mixed $default = null): mixed |
24 | 24 | { |
25 | - if (!isset($this->storage[$key])) { |
|
25 | + if (!isset($this->storage[$key])) |
|
26 | + { |
|
26 | 27 | return $default; |
27 | 28 | } |
28 | 29 | |
@@ -30,7 +31,8 @@ discard block |
||
30 | 31 | |
31 | 32 | $expiresAt = $item['timestamp'] ?? 0; |
32 | 33 | |
33 | - if ($expiresAt !== 0 && \time() >= $expiresAt) { |
|
34 | + if ($expiresAt !== 0 && \time() >= $expiresAt) |
|
35 | + { |
|
34 | 36 | $this->delete($key); |
35 | 37 | |
36 | 38 | return $default; |
@@ -51,7 +53,8 @@ discard block |
||
51 | 53 | |
52 | 54 | public function delete(string $key): bool |
53 | 55 | { |
54 | - if ($this->has($key)) { |
|
56 | + if ($this->has($key)) |
|
57 | + { |
|
55 | 58 | unset($this->storage[$key]); |
56 | 59 | |
57 | 60 | return true; |
@@ -71,7 +74,8 @@ discard block |
||
71 | 74 | { |
72 | 75 | $return = []; |
73 | 76 | |
74 | - foreach ($keys as $key) { |
|
77 | + foreach ($keys as $key) |
|
78 | + { |
|
75 | 79 | $return[$key] = $this->get($key, $default); |
76 | 80 | } |
77 | 81 | |
@@ -80,7 +84,8 @@ discard block |
||
80 | 84 | |
81 | 85 | public function setMultiple(iterable $values, null|int|\DateInterval|\DateTimeInterface $ttl = null): bool |
82 | 86 | { |
83 | - foreach ($values as $key => $value) { |
|
87 | + foreach ($values as $key => $value) |
|
88 | + { |
|
84 | 89 | $this->set($key, $value, $ttl); |
85 | 90 | } |
86 | 91 | |
@@ -91,7 +96,8 @@ discard block |
||
91 | 96 | { |
92 | 97 | $state = null; |
93 | 98 | |
94 | - foreach ($keys as $key) { |
|
99 | + foreach ($keys as $key) |
|
100 | + { |
|
95 | 101 | $result = $this->delete($key); |
96 | 102 | |
97 | 103 | $state = \is_null($state) ? $result : $result && $state; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | private readonly FilesInterface $files, |
17 | 17 | private readonly string $path, |
18 | 18 | private readonly int $ttl = 2_592_000 |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function get(string $key, mixed $default = null): mixed |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | return $this->getPayload($key)['value'] ?? $default; |
25 | 25 | } |
26 | 26 | |
27 | - public function set(string $key, mixed $value, null|int|\DateInterval|\DateTimeInterface $ttl = null): bool |
|
27 | + public function set(string $key, mixed $value, null | int | \DateInterval | \DateTimeInterface $ttl = null): bool |
|
28 | 28 | { |
29 | 29 | return $this->files->write( |
30 | 30 | $this->makePath($key), |
31 | - $this->ttlToTimestamp($ttl) . \serialize($value), |
|
31 | + $this->ttlToTimestamp($ttl).\serialize($value), |
|
32 | 32 | null, |
33 | 33 | true |
34 | 34 | ); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function delete(string $key): bool |
38 | 38 | { |
39 | - if ($this->has($key)) { |
|
39 | + if ($this->has($key)){ |
|
40 | 40 | return $this->files->delete($this->makePath($key)); |
41 | 41 | } |
42 | 42 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | public function clear(): bool |
47 | 47 | { |
48 | - if (!$this->files->isDirectory($this->path)) { |
|
48 | + if (!$this->files->isDirectory($this->path)){ |
|
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | |
@@ -58,18 +58,18 @@ discard block |
||
58 | 58 | { |
59 | 59 | $result = []; |
60 | 60 | |
61 | - foreach ($keys as $key) { |
|
61 | + foreach ($keys as $key){ |
|
62 | 62 | $result[$key] = $this->get($key, $default); |
63 | 63 | } |
64 | 64 | |
65 | 65 | return $result; |
66 | 66 | } |
67 | 67 | |
68 | - public function setMultiple(iterable $values, null|int|\DateInterval|\DateTimeInterface $ttl = null): bool |
|
68 | + public function setMultiple(iterable $values, null | int | \DateInterval | \DateTimeInterface $ttl = null): bool |
|
69 | 69 | { |
70 | 70 | $state = null; |
71 | 71 | |
72 | - foreach ($values as $key => $value) { |
|
72 | + foreach ($values as $key => $value){ |
|
73 | 73 | $result = $this->set($key, $value, $ttl); |
74 | 74 | $state = \is_null($state) ? $result : $result && $state; |
75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function deleteMultiple(iterable $keys): bool |
81 | 81 | { |
82 | 82 | $state = null; |
83 | - foreach ($keys as $key) { |
|
83 | + foreach ($keys as $key){ |
|
84 | 84 | $result = $this->delete($key); |
85 | 85 | $state = \is_null($state) ? $result : $result && $state; |
86 | 86 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | { |
101 | 101 | $parts = \array_slice(\str_split($hash = \sha1($key), 2), 0, 2); |
102 | 102 | |
103 | - return $this->path . '/' . \implode('/', $parts) . '/' . $hash; |
|
103 | + return $this->path.'/'.\implode('/', $parts).'/'.$hash; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,25 +110,25 @@ discard block |
||
110 | 110 | { |
111 | 111 | $path = $this->makePath($key); |
112 | 112 | |
113 | - try { |
|
114 | - $expire = (int) \substr( |
|
113 | + try{ |
|
114 | + $expire = (int)\substr( |
|
115 | 115 | $contents = $this->files->read($path), |
116 | 116 | 0, |
117 | 117 | 10 |
118 | 118 | ); |
119 | - } catch (FileNotFoundException) { |
|
119 | + }catch (FileNotFoundException){ |
|
120 | 120 | return $this->makeEmptyPayload(); |
121 | 121 | } |
122 | 122 | |
123 | - if (\time() >= $expire) { |
|
123 | + if (\time() >= $expire){ |
|
124 | 124 | $this->delete($key); |
125 | 125 | |
126 | 126 | return $this->makeEmptyPayload(); |
127 | 127 | } |
128 | 128 | |
129 | - try { |
|
129 | + try{ |
|
130 | 130 | $data = \unserialize(\substr($contents, 10)); |
131 | - } catch (\Exception) { |
|
131 | + }catch (\Exception){ |
|
132 | 132 | $this->delete($key); |
133 | 133 | |
134 | 134 | return $this->makeEmptyPayload(); |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | |
37 | 37 | public function delete(string $key): bool |
38 | 38 | { |
39 | - if ($this->has($key)) { |
|
39 | + if ($this->has($key)) |
|
40 | + { |
|
40 | 41 | return $this->files->delete($this->makePath($key)); |
41 | 42 | } |
42 | 43 | |
@@ -45,7 +46,8 @@ discard block |
||
45 | 46 | |
46 | 47 | public function clear(): bool |
47 | 48 | { |
48 | - if (!$this->files->isDirectory($this->path)) { |
|
49 | + if (!$this->files->isDirectory($this->path)) |
|
50 | + { |
|
49 | 51 | return false; |
50 | 52 | } |
51 | 53 | |
@@ -58,7 +60,8 @@ discard block |
||
58 | 60 | { |
59 | 61 | $result = []; |
60 | 62 | |
61 | - foreach ($keys as $key) { |
|
63 | + foreach ($keys as $key) |
|
64 | + { |
|
62 | 65 | $result[$key] = $this->get($key, $default); |
63 | 66 | } |
64 | 67 | |
@@ -69,7 +72,8 @@ discard block |
||
69 | 72 | { |
70 | 73 | $state = null; |
71 | 74 | |
72 | - foreach ($values as $key => $value) { |
|
75 | + foreach ($values as $key => $value) |
|
76 | + { |
|
73 | 77 | $result = $this->set($key, $value, $ttl); |
74 | 78 | $state = \is_null($state) ? $result : $result && $state; |
75 | 79 | } |
@@ -80,7 +84,8 @@ discard block |
||
80 | 84 | public function deleteMultiple(iterable $keys): bool |
81 | 85 | { |
82 | 86 | $state = null; |
83 | - foreach ($keys as $key) { |
|
87 | + foreach ($keys as $key) |
|
88 | + { |
|
84 | 89 | $result = $this->delete($key); |
85 | 90 | $state = \is_null($state) ? $result : $result && $state; |
86 | 91 | } |
@@ -110,25 +115,32 @@ discard block |
||
110 | 115 | { |
111 | 116 | $path = $this->makePath($key); |
112 | 117 | |
113 | - try { |
|
118 | + try |
|
119 | + { |
|
114 | 120 | $expire = (int) \substr( |
115 | 121 | $contents = $this->files->read($path), |
116 | 122 | 0, |
117 | 123 | 10 |
118 | 124 | ); |
119 | - } catch (FileNotFoundException) { |
|
125 | + } |
|
126 | + catch (FileNotFoundException) |
|
127 | + { |
|
120 | 128 | return $this->makeEmptyPayload(); |
121 | 129 | } |
122 | 130 | |
123 | - if (\time() >= $expire) { |
|
131 | + if (\time() >= $expire) |
|
132 | + { |
|
124 | 133 | $this->delete($key); |
125 | 134 | |
126 | 135 | return $this->makeEmptyPayload(); |
127 | 136 | } |
128 | 137 | |
129 | - try { |
|
138 | + try |
|
139 | + { |
|
130 | 140 | $data = \unserialize(\substr($contents, 10)); |
131 | - } catch (\Exception) { |
|
141 | + } |
|
142 | + catch (\Exception) |
|
143 | + { |
|
132 | 144 | $this->delete($key); |
133 | 145 | |
134 | 146 | return $this->makeEmptyPayload(); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | public function __construct( |
30 | 30 | private readonly ConfiguratorInterface $config |
31 | - ) { |
|
31 | + ){ |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function registerTypeAlias(string $storageClass, string $alias): void |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | ): CacheManager { |
57 | 57 | $manager = new CacheManager($config, $factory); |
58 | 58 | |
59 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
59 | + foreach ($config->getAliases() as $alias => $storageName){ |
|
60 | 60 | $binder->bind( |
61 | 61 | $alias, |
62 | 62 | static fn (CacheManager $manager): CacheInterface => $manager->storage($storageName) |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ], |
80 | 80 | 'file' => [ |
81 | 81 | 'type' => 'file', |
82 | - 'path' => $dirs->get('runtime') . 'cache', |
|
82 | + 'path' => $dirs->get('runtime').'cache', |
|
83 | 83 | ], |
84 | 84 | ], |
85 | 85 | 'typeAliases' => [ |
@@ -56,7 +56,8 @@ |
||
56 | 56 | ): CacheManager { |
57 | 57 | $manager = new CacheManager($config, $factory); |
58 | 58 | |
59 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
59 | + foreach ($config->getAliases() as $alias => $storageName) |
|
60 | + { |
|
60 | 61 | $binder->bind( |
61 | 62 | $alias, |
62 | 63 | static fn (CacheManager $manager): CacheInterface => $manager->storage($storageName) |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | $doc = $this->parse('<a href="url"></a>'); |
33 | 33 | |
34 | 34 | $t = new Traverser(); |
35 | - $t->addVisitor(new class() implements VisitorInterface { |
|
35 | + $t->addVisitor(new class() implements VisitorInterface{ |
|
36 | 36 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
37 | 37 | { |
38 | - if ($node instanceof Tag && $node->name === 'a') { |
|
38 | + if ($node instanceof Tag && $node->name === 'a'){ |
|
39 | 39 | $node->name = 'b'; |
40 | 40 | } |
41 | 41 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $doc = $this->parse('<a href="url"></a>'); |
62 | 62 | |
63 | 63 | $t = new Traverser(); |
64 | - $t->addVisitor(new class() implements VisitorInterface { |
|
64 | + $t->addVisitor(new class() implements VisitorInterface{ |
|
65 | 65 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
66 | 66 | { |
67 | 67 | return null; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
71 | 71 | { |
72 | - if ($node instanceof Tag && $node->name === 'a') { |
|
72 | + if ($node instanceof Tag && $node->name === 'a'){ |
|
73 | 73 | $new = new Tag(); |
74 | 74 | $new->name = 'link'; |
75 | 75 | $new->void = true; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $doc = $this->parse('<a href="url"><b></b>hello</a>'); |
95 | 95 | |
96 | 96 | $t = new Traverser(); |
97 | - $t->addVisitor(new class() implements VisitorInterface { |
|
97 | + $t->addVisitor(new class() implements VisitorInterface{ |
|
98 | 98 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
99 | 99 | { |
100 | 100 | return null; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
104 | 104 | { |
105 | - if ($node instanceof Tag && $node->name === 'b') { |
|
105 | + if ($node instanceof Tag && $node->name === 'b'){ |
|
106 | 106 | return VisitorInterface::REMOVE_NODE; |
107 | 107 | } |
108 | 108 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
132 | 132 | { |
133 | - if ($ctx->getCurrentNode() instanceof Raw) { |
|
133 | + if ($ctx->getCurrentNode() instanceof Raw){ |
|
134 | 134 | $this->assertInstanceOf(Tag::class, $ctx->getParentNode()); |
135 | 135 | $this->assertSame('b', $ctx->getParentNode()->name); |
136 | 136 |
@@ -32,10 +32,12 @@ discard block |
||
32 | 32 | $doc = $this->parse('<a href="url"></a>'); |
33 | 33 | |
34 | 34 | $t = new Traverser(); |
35 | - $t->addVisitor(new class() implements VisitorInterface { |
|
35 | + $t->addVisitor(new class() implements VisitorInterface |
|
36 | + { |
|
36 | 37 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
37 | 38 | { |
38 | - if ($node instanceof Tag && $node->name === 'a') { |
|
39 | + if ($node instanceof Tag && $node->name === 'a') |
|
40 | + { |
|
39 | 41 | $node->name = 'b'; |
40 | 42 | } |
41 | 43 | |
@@ -61,7 +63,8 @@ discard block |
||
61 | 63 | $doc = $this->parse('<a href="url"></a>'); |
62 | 64 | |
63 | 65 | $t = new Traverser(); |
64 | - $t->addVisitor(new class() implements VisitorInterface { |
|
66 | + $t->addVisitor(new class() implements VisitorInterface |
|
67 | + { |
|
65 | 68 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
66 | 69 | { |
67 | 70 | return null; |
@@ -69,7 +72,8 @@ discard block |
||
69 | 72 | |
70 | 73 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
71 | 74 | { |
72 | - if ($node instanceof Tag && $node->name === 'a') { |
|
75 | + if ($node instanceof Tag && $node->name === 'a') |
|
76 | + { |
|
73 | 77 | $new = new Tag(); |
74 | 78 | $new->name = 'link'; |
75 | 79 | $new->void = true; |
@@ -94,7 +98,8 @@ discard block |
||
94 | 98 | $doc = $this->parse('<a href="url"><b></b>hello</a>'); |
95 | 99 | |
96 | 100 | $t = new Traverser(); |
97 | - $t->addVisitor(new class() implements VisitorInterface { |
|
101 | + $t->addVisitor(new class() implements VisitorInterface |
|
102 | + { |
|
98 | 103 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
99 | 104 | { |
100 | 105 | return null; |
@@ -102,7 +107,8 @@ discard block |
||
102 | 107 | |
103 | 108 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
104 | 109 | { |
105 | - if ($node instanceof Tag && $node->name === 'b') { |
|
110 | + if ($node instanceof Tag && $node->name === 'b') |
|
111 | + { |
|
106 | 112 | return VisitorInterface::REMOVE_NODE; |
107 | 113 | } |
108 | 114 | |
@@ -130,7 +136,8 @@ discard block |
||
130 | 136 | |
131 | 137 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
132 | 138 | { |
133 | - if ($ctx->getCurrentNode() instanceof Raw) { |
|
139 | + if ($ctx->getCurrentNode() instanceof Raw) |
|
140 | + { |
|
134 | 141 | $this->assertInstanceOf(Tag::class, $ctx->getParentNode()); |
135 | 142 | $this->assertSame('b', $ctx->getParentNode()->name); |
136 | 143 |