@@ -43,7 +43,8 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | public function addRole(string $role): PermissionManager |
| 45 | 45 | { |
| 46 | - if ($this->hasRole($role)) { |
|
| 46 | + if ($this->hasRole($role)) |
|
| 47 | + { |
|
| 47 | 48 | throw new RoleException(\sprintf("Role '%s' already exists", $role)); |
| 48 | 49 | } |
| 49 | 50 | |
@@ -56,7 +57,8 @@ discard block |
||
| 56 | 57 | |
| 57 | 58 | public function removeRole(string $role): PermissionManager |
| 58 | 59 | { |
| 59 | - if (!$this->hasRole($role)) { |
|
| 60 | + if (!$this->hasRole($role)) |
|
| 61 | + { |
|
| 60 | 62 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 61 | 63 | } |
| 62 | 64 | |
@@ -72,7 +74,8 @@ discard block |
||
| 72 | 74 | |
| 73 | 75 | public function getPermissions(string $role): array |
| 74 | 76 | { |
| 75 | - if (!$this->hasRole($role)) { |
|
| 77 | + if (!$this->hasRole($role)) |
|
| 78 | + { |
|
| 76 | 79 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 77 | 80 | } |
| 78 | 81 | |
@@ -81,7 +84,8 @@ discard block |
||
| 81 | 84 | |
| 82 | 85 | public function getRule(string $role, string $permission): RuleInterface |
| 83 | 86 | { |
| 84 | - if (!$this->hasRole($role)) { |
|
| 87 | + if (!$this->hasRole($role)) |
|
| 88 | + { |
|
| 85 | 89 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 86 | 90 | } |
| 87 | 91 | |
@@ -91,11 +95,13 @@ discard block |
||
| 91 | 95 | |
| 92 | 96 | public function associate(string $role, string $permission, string $rule = AllowRule::class): PermissionManager |
| 93 | 97 | { |
| 94 | - if (!$this->hasRole($role)) { |
|
| 98 | + if (!$this->hasRole($role)) |
|
| 99 | + { |
|
| 95 | 100 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 96 | 101 | } |
| 97 | 102 | |
| 98 | - if (!$this->rules->has($rule)) { |
|
| 103 | + if (!$this->rules->has($rule)) |
|
| 104 | + { |
|
| 99 | 105 | throw new PermissionException(\sprintf("Undefined rule '%s'", $rule)); |
| 100 | 106 | } |
| 101 | 107 | |
@@ -121,14 +127,17 @@ discard block |
||
| 121 | 127 | */ |
| 122 | 128 | private function findRule(string $role, string $permission): string |
| 123 | 129 | { |
| 124 | - if (isset($this->permissions[$role][$permission])) { |
|
| 130 | + if (isset($this->permissions[$role][$permission])) |
|
| 131 | + { |
|
| 125 | 132 | //O(1) check |
| 126 | 133 | return $this->permissions[$role][$permission]; |
| 127 | 134 | } |
| 128 | 135 | |
| 129 | 136 | //Matching using star syntax |
| 130 | - foreach ($this->permissions[$role] as $pattern => $rule) { |
|
| 131 | - if ($this->matcher->matches($permission, $pattern)) { |
|
| 137 | + foreach ($this->permissions[$role] as $pattern => $rule) |
|
| 138 | + { |
|
| 139 | + if ($this->matcher->matches($permission, $pattern)) |
|
| 140 | + { |
|
| 132 | 141 | return $rule; |
| 133 | 142 | } |
| 134 | 143 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | public function __construct( |
| 35 | 35 | private readonly RulesInterface $rules, |
| 36 | 36 | private readonly string $defaultRule = ForbidRule::class, |
| 37 | - ) { |
|
| 37 | + ){ |
|
| 38 | 38 | $this->matcher = new Matcher(); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public function addRole(string $role): PermissionManager |
| 47 | 47 | { |
| 48 | - if ($this->hasRole($role)) { |
|
| 48 | + if ($this->hasRole($role)){ |
|
| 49 | 49 | throw new RoleException(\sprintf("Role '%s' already exists", $role)); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function removeRole(string $role): PermissionManager |
| 60 | 60 | { |
| 61 | - if (!$this->hasRole($role)) { |
|
| 61 | + if (!$this->hasRole($role)){ |
|
| 62 | 62 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | public function getPermissions(string $role): array |
| 76 | 76 | { |
| 77 | - if (!$this->hasRole($role)) { |
|
| 77 | + if (!$this->hasRole($role)){ |
|
| 78 | 78 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | public function getRule(string $role, string $permission): RuleInterface |
| 85 | 85 | { |
| 86 | - if (!$this->hasRole($role)) { |
|
| 86 | + if (!$this->hasRole($role)){ |
|
| 87 | 87 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | public function associate(string $role, string $permission, string $rule = AllowRule::class): PermissionManager |
| 95 | 95 | { |
| 96 | - if (!$this->hasRole($role)) { |
|
| 96 | + if (!$this->hasRole($role)){ |
|
| 97 | 97 | throw new RoleException(\sprintf("Undefined role '%s'", $role)); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if (!$this->rules->has($rule)) { |
|
| 100 | + if (!$this->rules->has($rule)){ |
|
| 101 | 101 | throw new PermissionException(\sprintf("Undefined rule '%s'", $rule)); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -122,14 +122,14 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | private function findRule(string $role, string $permission): string |
| 124 | 124 | { |
| 125 | - if (isset($this->permissions[$role][$permission])) { |
|
| 125 | + if (isset($this->permissions[$role][$permission])){ |
|
| 126 | 126 | //O(1) check |
| 127 | 127 | return $this->permissions[$role][$permission]; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | //Matching using star syntax |
| 131 | - foreach ($this->permissions[$role] as $pattern => $rule) { |
|
| 132 | - if ($this->matcher->matches($permission, $pattern)) { |
|
| 131 | + foreach ($this->permissions[$role] as $pattern => $rule){ |
|
| 132 | + if ($this->matcher->matches($permission, $pattern)){ |
|
| 133 | 133 | return $rule; |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -28,16 +28,16 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $role = $this->argument('role'); |
| 30 | 30 | |
| 31 | - if ($role !== null && !$rbac->hasRole($role)) { |
|
| 31 | + if ($role !== null && !$rbac->hasRole($role)){ |
|
| 32 | 32 | throw new CommandException('Unknown role provided'); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ($role !== null) { |
|
| 35 | + if ($role !== null){ |
|
| 36 | 36 | $rows = $this->getRolePermissions($role, $rbac); |
| 37 | - } else { |
|
| 37 | + }else{ |
|
| 38 | 38 | $rows = []; |
| 39 | 39 | |
| 40 | - foreach ($rbac->getRoles() as $role) { |
|
| 40 | + foreach ($rbac->getRoles() as $role){ |
|
| 41 | 41 | /** @noinspection SlowArrayOperationsInLoopInspection */ |
| 42 | 42 | $rows = \array_merge( |
| 43 | 43 | $this->getRolePermissions($role, $rbac), |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | $permissions = []; |
| 65 | 65 | |
| 66 | - foreach ($rbac->getPermissions($role) as $permission => $rule) { |
|
| 66 | + foreach ($rbac->getPermissions($role) as $permission => $rule){ |
|
| 67 | 67 | $permissions[] = [ |
| 68 | 68 | 'role' => $role, |
| 69 | 69 | 'permission' => $permission, |
@@ -28,16 +28,21 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $role = $this->argument('role'); |
| 30 | 30 | |
| 31 | - if ($role !== null && !$rbac->hasRole($role)) { |
|
| 31 | + if ($role !== null && !$rbac->hasRole($role)) |
|
| 32 | + { |
|
| 32 | 33 | throw new CommandException('Unknown role provided'); |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | - if ($role !== null) { |
|
| 36 | + if ($role !== null) |
|
| 37 | + { |
|
| 36 | 38 | $rows = $this->getRolePermissions($role, $rbac); |
| 37 | - } else { |
|
| 39 | + } |
|
| 40 | + else |
|
| 41 | + { |
|
| 38 | 42 | $rows = []; |
| 39 | 43 | |
| 40 | - foreach ($rbac->getRoles() as $role) { |
|
| 44 | + foreach ($rbac->getRoles() as $role) |
|
| 45 | + { |
|
| 41 | 46 | /** @noinspection SlowArrayOperationsInLoopInspection */ |
| 42 | 47 | $rows = \array_merge( |
| 43 | 48 | $this->getRolePermissions($role, $rbac), |
@@ -63,7 +68,8 @@ discard block |
||
| 63 | 68 | { |
| 64 | 69 | $permissions = []; |
| 65 | 70 | |
| 66 | - foreach ($rbac->getPermissions($role) as $permission => $rule) { |
|
| 71 | + foreach ($rbac->getPermissions($role) as $permission => $rule) |
|
| 72 | + { |
|
| 67 | 73 | $permissions[] = [ |
| 68 | 74 | 'role' => $role, |
| 69 | 75 | 'permission' => $permission, |
@@ -22,13 +22,17 @@ |
||
| 22 | 22 | |
| 23 | 23 | public function getHandler(string $jobType): HandlerInterface |
| 24 | 24 | { |
| 25 | - try { |
|
| 25 | + try |
|
| 26 | + { |
|
| 26 | 27 | $handler = $this->container->get($this->className($jobType)); |
| 27 | - } catch (ContainerException $e) { |
|
| 28 | + } |
|
| 29 | + catch (ContainerException $e) |
|
| 30 | + { |
|
| 28 | 31 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - if (!$handler instanceof HandlerInterface) { |
|
| 34 | + if (!$handler instanceof HandlerInterface) |
|
| 35 | + { |
|
| 32 | 36 | throw new JobException(\sprintf('Unable to resolve job handler for `%s`', $jobType)); |
| 33 | 37 | } |
| 34 | 38 | |
@@ -16,19 +16,19 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function __construct( |
| 18 | 18 | private readonly ContainerInterface $container, |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | $this->inflector = (new InflectorFactory())->build(); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function getHandler(string $jobType): HandlerInterface |
| 24 | 24 | { |
| 25 | - try { |
|
| 25 | + try{ |
|
| 26 | 26 | $handler = $this->container->get($this->className($jobType)); |
| 27 | - } catch (ContainerException $e) { |
|
| 27 | + }catch (ContainerException $e){ |
|
| 28 | 28 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if (!$handler instanceof HandlerInterface) { |
|
| 31 | + if (!$handler instanceof HandlerInterface){ |
|
| 32 | 32 | throw new JobException(\sprintf('Unable to resolve job handler for `%s`', $jobType)); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -58,11 +58,13 @@ discard block |
||
| 58 | 58 | $declarator = new DeclareClass(); |
| 59 | 59 | $this->traverse($filename, $declarator); |
| 60 | 60 | |
| 61 | - if (empty($declarator->getClass())) { |
|
| 61 | + if (empty($declarator->getClass())) |
|
| 62 | + { |
|
| 62 | 63 | throw new ClassNotDeclaredException($filename); |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | - if ($declarator->getNamespace()) { |
|
| 66 | + if ($declarator->getNamespace()) |
|
| 67 | + { |
|
| 66 | 68 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 67 | 69 | } |
| 68 | 70 | |
@@ -73,7 +75,8 @@ discard block |
||
| 73 | 75 | { |
| 74 | 76 | $tr = new NodeTraverser(); |
| 75 | 77 | |
| 76 | - foreach ($visitors as $visitor) { |
|
| 78 | + foreach ($visitors as $visitor) |
|
| 79 | + { |
|
| 77 | 80 | $tr->addVisitor($visitor); |
| 78 | 81 | } |
| 79 | 82 | |
@@ -82,7 +85,8 @@ discard block |
||
| 82 | 85 | |
| 83 | 86 | private function fillStmts(ClassNode $definition, array $imports): void |
| 84 | 87 | { |
| 85 | - foreach ($imports as $import) { |
|
| 88 | + foreach ($imports as $import) |
|
| 89 | + { |
|
| 86 | 90 | $definition->addImportUsage($import['name'], $import['alias']); |
| 87 | 91 | } |
| 88 | 92 | } |
@@ -95,10 +99,12 @@ discard block |
||
| 95 | 99 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 96 | 100 | |
| 97 | 101 | $constructor = $reflection->getConstructor(); |
| 98 | - if ($constructor !== null) { |
|
| 102 | + if ($constructor !== null) |
|
| 103 | + { |
|
| 99 | 104 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 100 | 105 | |
| 101 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 106 | + foreach ($reflection->getConstructor()->getParameters() as $parameter) |
|
| 107 | + { |
|
| 102 | 108 | $definition->addParam($parameter); |
| 103 | 109 | } |
| 104 | 110 | } |
@@ -110,8 +116,10 @@ discard block |
||
| 110 | 116 | */ |
| 111 | 117 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 112 | 118 | { |
| 113 | - foreach ($vars as $k => $var) { |
|
| 114 | - if (isset($definition->constructorParams[$var])) { |
|
| 119 | + foreach ($vars as $k => $var) |
|
| 120 | + { |
|
| 121 | + if (isset($definition->constructorParams[$var])) |
|
| 122 | + { |
|
| 115 | 123 | unset($vars[$k]); |
| 116 | 124 | } |
| 117 | 125 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private readonly ConflictResolver\Names $namesResolver, |
| 26 | 26 | private readonly ConflictResolver\Namespaces $namespacesResolver, |
| 27 | 27 | ?Parser $parser = null, |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->parser = $parser ?? (new ParserFactory())->createForHostVersion(); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | $declarator = new DeclareClass(); |
| 61 | 61 | $this->traverse($filename, $declarator); |
| 62 | 62 | |
| 63 | - if (empty($declarator->getClass())) { |
|
| 63 | + if (empty($declarator->getClass())){ |
|
| 64 | 64 | throw new ClassNotDeclaredException($filename); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ($declarator->getNamespace()) { |
|
| 67 | + if ($declarator->getNamespace()){ |
|
| 68 | 68 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $tr = new NodeTraverser(); |
| 77 | 77 | |
| 78 | - foreach ($visitors as $visitor) { |
|
| 78 | + foreach ($visitors as $visitor){ |
|
| 79 | 79 | $tr->addVisitor($visitor); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | private function fillStmts(ClassNode $definition, array $imports): void |
| 86 | 86 | { |
| 87 | - foreach ($imports as $import) { |
|
| 87 | + foreach ($imports as $import){ |
|
| 88 | 88 | $definition->addImportUsage($import['name'], $import['alias']); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 98 | 98 | |
| 99 | 99 | $constructor = $reflection->getConstructor(); |
| 100 | - if ($constructor !== null) { |
|
| 100 | + if ($constructor !== null){ |
|
| 101 | 101 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 102 | 102 | |
| 103 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 103 | + foreach ($reflection->getConstructor()->getParameters() as $parameter){ |
|
| 104 | 104 | $definition->addParam($parameter); |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 114 | 114 | { |
| 115 | - foreach ($vars as $k => $var) { |
|
| 116 | - if (isset($definition->constructorParams[$var])) { |
|
| 115 | + foreach ($vars as $k => $var){ |
|
| 116 | + if (isset($definition->constructorParams[$var])){ |
|
| 117 | 117 | unset($vars[$k]); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function leaveNode(Node $node): ?Node |
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Class_){ |
|
| 20 | 20 | return null; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | $placementID = 0; |
| 24 | - foreach ($node->stmts as $index => $child) { |
|
| 24 | + foreach ($node->stmts as $index => $child){ |
|
| 25 | 25 | $placementID = $index; |
| 26 | - if ($child instanceof Node\Stmt\ClassMethod) { |
|
| 27 | - if ($child->name->name === '__construct') { |
|
| 26 | + if ($child instanceof Node\Stmt\ClassMethod){ |
|
| 27 | + if ($child->name->name === '__construct'){ |
|
| 28 | 28 | $node->setAttribute('constructor', $child); |
| 29 | 29 | |
| 30 | 30 | return null; |
@@ -16,15 +16,19 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function leaveNode(Node $node): ?Node |
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Class_) |
|
| 20 | + { |
|
| 20 | 21 | return null; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | $placementID = 0; |
| 24 | - foreach ($node->stmts as $index => $child) { |
|
| 25 | + foreach ($node->stmts as $index => $child) |
|
| 26 | + { |
|
| 25 | 27 | $placementID = $index; |
| 26 | - if ($child instanceof Node\Stmt\ClassMethod) { |
|
| 27 | - if ($child->name->name === '__construct') { |
|
| 28 | + if ($child instanceof Node\Stmt\ClassMethod) |
|
| 29 | + { |
|
| 30 | + if ($child->name->name === '__construct') |
|
| 31 | + { |
|
| 28 | 32 | $node->setAttribute('constructor', $child); |
| 29 | 33 | |
| 30 | 34 | return null; |
@@ -14,19 +14,19 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | final class RemoveUse extends NodeVisitorAbstract |
| 16 | 16 | { |
| 17 | - public function leaveNode(Node $node): int|Node|null |
|
| 17 | + public function leaveNode(Node $node): int | Node | null |
|
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Use_){ |
|
| 20 | 20 | return null; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - foreach ($node->uses as $index => $use) { |
|
| 24 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
| 23 | + foreach ($node->uses as $index => $use){ |
|
| 24 | + if ($use->name->toString() === PrototypeTrait::class){ |
|
| 25 | 25 | unset($node->uses[$index]); |
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if (empty($node->uses)) { |
|
| 29 | + if (empty($node->uses)){ |
|
| 30 | 30 | return NodeTraverser::REMOVE_NODE; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -16,17 +16,21 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function leaveNode(Node $node): int|Node|null |
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Use_) |
|
| 20 | + { |
|
| 20 | 21 | return null; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - foreach ($node->uses as $index => $use) { |
|
| 24 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
| 24 | + foreach ($node->uses as $index => $use) |
|
| 25 | + { |
|
| 26 | + if ($use->name->toString() === PrototypeTrait::class) |
|
| 27 | + { |
|
| 25 | 28 | unset($node->uses[$index]); |
| 26 | 29 | } |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | - if (empty($node->uses)) { |
|
| 32 | + if (empty($node->uses)) |
|
| 33 | + { |
|
| 30 | 34 | return NodeTraverser::REMOVE_NODE; |
| 31 | 35 | } |
| 32 | 36 | |
@@ -14,21 +14,21 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function find(array $sequences, int $originSequence): int |
| 16 | 16 | { |
| 17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
| 17 | + if (empty($sequences) || $originSequence > \max($sequences)){ |
|
| 18 | 18 | return $originSequence; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | $gaps = $this->skippedSequences($sequences); |
| 22 | 22 | |
| 23 | - if (isset($gaps[$originSequence])) { |
|
| 23 | + if (isset($gaps[$originSequence])){ |
|
| 24 | 24 | return $originSequence; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
| 28 | 28 | unset($gaps[1]); |
| 29 | - if (empty($gaps)) { |
|
| 29 | + if (empty($gaps)){ |
|
| 30 | 30 | $max = \max($sequences); |
| 31 | - if ($max === 0) { |
|
| 31 | + if ($max === 0){ |
|
| 32 | 32 | return 2; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $skipped = []; |
| 44 | 44 | $max = \max($sequences); |
| 45 | - for ($i = 0; $i < $max; $i++) { |
|
| 46 | - if (!\in_array($i, $sequences, true)) { |
|
| 45 | + for ($i = 0; $i < $max; $i++){ |
|
| 46 | + if (!\in_array($i, $sequences, true)){ |
|
| 47 | 47 | $skipped[$i] = $i; |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -14,21 +14,25 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function find(array $sequences, int $originSequence): int |
| 16 | 16 | { |
| 17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
| 17 | + if (empty($sequences) || $originSequence > \max($sequences)) |
|
| 18 | + { |
|
| 18 | 19 | return $originSequence; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | 22 | $gaps = $this->skippedSequences($sequences); |
| 22 | 23 | |
| 23 | - if (isset($gaps[$originSequence])) { |
|
| 24 | + if (isset($gaps[$originSequence])) |
|
| 25 | + { |
|
| 24 | 26 | return $originSequence; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
| 28 | 30 | unset($gaps[1]); |
| 29 | - if (empty($gaps)) { |
|
| 31 | + if (empty($gaps)) |
|
| 32 | + { |
|
| 30 | 33 | $max = \max($sequences); |
| 31 | - if ($max === 0) { |
|
| 34 | + if ($max === 0) |
|
| 35 | + { |
|
| 32 | 36 | return 2; |
| 33 | 37 | } |
| 34 | 38 | |
@@ -42,8 +46,10 @@ discard block |
||
| 42 | 46 | { |
| 43 | 47 | $skipped = []; |
| 44 | 48 | $max = \max($sequences); |
| 45 | - for ($i = 0; $i < $max; $i++) { |
|
| 46 | - if (!\in_array($i, $sequences, true)) { |
|
| 49 | + for ($i = 0; $i < $max; $i++) |
|
| 50 | + { |
|
| 51 | + if (!\in_array($i, $sequences, true)) |
|
| 52 | + { |
|
| 47 | 53 | $skipped[$i] = $i; |
| 48 | 54 | } |
| 49 | 55 | } |
@@ -46,7 +46,8 @@ discard block |
||
| 46 | 46 | public function perform(): int |
| 47 | 47 | { |
| 48 | 48 | $prototyped = $this->locator->getTargetClasses(); |
| 49 | - if ($prototyped === []) { |
|
| 49 | + if ($prototyped === []) |
|
| 50 | + { |
|
| 50 | 51 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 51 | 52 | |
| 52 | 53 | return self::SUCCESS; |
@@ -54,18 +55,23 @@ discard block |
||
| 54 | 55 | |
| 55 | 56 | $targets = []; |
| 56 | 57 | |
| 57 | - foreach ($prototyped as $class) { |
|
| 58 | + foreach ($prototyped as $class) |
|
| 59 | + { |
|
| 58 | 60 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 59 | - if (empty($proto)) { |
|
| 61 | + if (empty($proto)) |
|
| 62 | + { |
|
| 60 | 63 | $modified = $this->modify($class, $proto); |
| 61 | - if ($modified !== null) { |
|
| 64 | + if ($modified !== null) |
|
| 65 | + { |
|
| 62 | 66 | $targets[] = $modified; |
| 63 | 67 | } |
| 64 | 68 | continue; |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | - foreach ($proto as $target) { |
|
| 68 | - if ($target instanceof \Throwable) { |
|
| 71 | + foreach ($proto as $target) |
|
| 72 | + { |
|
| 73 | + if ($target instanceof \Throwable) |
|
| 74 | + { |
|
| 69 | 75 | $targets[] = [ |
| 70 | 76 | $class->getName(), |
| 71 | 77 | $target->getMessage(), |
@@ -74,7 +80,8 @@ discard block |
||
| 74 | 80 | continue 2; |
| 75 | 81 | } |
| 76 | 82 | |
| 77 | - if ($target === null) { |
|
| 83 | + if ($target === null) |
|
| 84 | + { |
|
| 78 | 85 | continue 2; |
| 79 | 86 | } |
| 80 | 87 | } |
@@ -82,14 +89,17 @@ discard block |
||
| 82 | 89 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 83 | 90 | |
| 84 | 91 | $modified = $this->modify($class, $proto); |
| 85 | - if ($modified !== null) { |
|
| 92 | + if ($modified !== null) |
|
| 93 | + { |
|
| 86 | 94 | $targets[] = $modified; |
| 87 | 95 | } |
| 88 | 96 | } |
| 89 | 97 | |
| 90 | - if (!empty($targets)) { |
|
| 98 | + if (!empty($targets)) |
|
| 99 | + { |
|
| 91 | 100 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 92 | - foreach ($targets as $target) { |
|
| 101 | + foreach ($targets as $target) |
|
| 102 | + { |
|
| 93 | 103 | $grid->addRow($target); |
| 94 | 104 | } |
| 95 | 105 | |
@@ -102,7 +112,8 @@ discard block |
||
| 102 | 112 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 103 | 113 | { |
| 104 | 114 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
| 105 | - try { |
|
| 115 | + try |
|
| 116 | + { |
|
| 106 | 117 | $modified = $this->injector->injectDependencies( |
| 107 | 118 | \file_get_contents($class->getFileName()), |
| 108 | 119 | $classDefinition, |
@@ -114,7 +125,9 @@ discard block |
||
| 114 | 125 | \file_put_contents($class->getFileName(), $modified); |
| 115 | 126 | |
| 116 | 127 | return null; |
| 117 | - } catch (\Throwable $e) { |
|
| 128 | + } |
|
| 129 | + catch (\Throwable $e) |
|
| 130 | + { |
|
| 118 | 131 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
| 119 | 132 | } |
| 120 | 133 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function perform(): int |
| 36 | 36 | { |
| 37 | 37 | $prototyped = $this->locator->getTargetClasses(); |
| 38 | - if ($prototyped === []) { |
|
| 38 | + if ($prototyped === []){ |
|
| 39 | 39 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 40 | 40 | |
| 41 | 41 | return self::SUCCESS; |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | $targets = []; |
| 45 | 45 | |
| 46 | - foreach ($prototyped as $class) { |
|
| 46 | + foreach ($prototyped as $class){ |
|
| 47 | 47 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 48 | - if (empty($proto)) { |
|
| 48 | + if (empty($proto)){ |
|
| 49 | 49 | $modified = $this->modify($class, $proto); |
| 50 | - if ($modified !== null) { |
|
| 50 | + if ($modified !== null){ |
|
| 51 | 51 | $targets[] = $modified; |
| 52 | 52 | } |
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - foreach ($proto as $target) { |
|
| 57 | - if ($target instanceof \Throwable) { |
|
| 56 | + foreach ($proto as $target){ |
|
| 57 | + if ($target instanceof \Throwable){ |
|
| 58 | 58 | $targets[] = [ |
| 59 | 59 | $class->getName(), |
| 60 | 60 | $target->getMessage(), |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | continue 2; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ($target === null) { |
|
| 66 | + if ($target === null){ |
|
| 67 | 67 | continue 2; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 72 | 72 | |
| 73 | 73 | $modified = $this->modify($class, $proto); |
| 74 | - if ($modified !== null) { |
|
| 74 | + if ($modified !== null){ |
|
| 75 | 75 | $targets[] = $modified; |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if (!empty($targets)) { |
|
| 79 | + if (!empty($targets)){ |
|
| 80 | 80 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 81 | - foreach ($targets as $target) { |
|
| 81 | + foreach ($targets as $target){ |
|
| 82 | 82 | $grid->addRow($target); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 92 | 92 | { |
| 93 | 93 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
| 94 | - try { |
|
| 94 | + try{ |
|
| 95 | 95 | $modified = $this->injector->injectDependencies( |
| 96 | 96 | \file_get_contents($class->getFileName()), |
| 97 | 97 | $classDefinition, |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | \file_put_contents($class->getFileName(), $modified); |
| 102 | 102 | |
| 103 | 103 | return null; |
| 104 | - } catch (\Throwable $e) { |
|
| 104 | + }catch (\Throwable $e){ |
|
| 105 | 105 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -28,7 +28,8 @@ |
||
| 28 | 28 | |
| 29 | 29 | protected function getMutator(string $field, string $type): mixed |
| 30 | 30 | { |
| 31 | - if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) { |
|
| 31 | + if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) |
|
| 32 | + { |
|
| 32 | 33 | return $this->schema[ModelSchema::MUTATORS][$type][$field]; |
| 33 | 34 | } |
| 34 | 35 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | array $data, |
| 14 | 14 | private array $schema, |
| 15 | - ) { |
|
| 15 | + ){ |
|
| 16 | 16 | parent::__construct($data); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | protected function getMutator(string $field, string $type): mixed |
| 30 | 30 | { |
| 31 | - if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) { |
|
| 31 | + if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])){ |
|
| 32 | 32 | return $this->schema[ModelSchema::MUTATORS][$type][$field]; |
| 33 | 33 | } |
| 34 | 34 | |