@@ -56,9 +56,12 @@ discard block |
||
| 56 | 56 | ); |
| 57 | 57 | $class->setLogger($logger); |
| 58 | 58 | |
| 59 | - try { |
|
| 59 | + try |
|
| 60 | + { |
|
| 60 | 61 | $ref->invoke($class, 'foo'); |
| 61 | - } catch (LocatorException) { |
|
| 62 | + } |
|
| 63 | + catch (LocatorException) |
|
| 64 | + { |
|
| 62 | 65 | } |
| 63 | 66 | } |
| 64 | 67 | |
@@ -71,9 +74,12 @@ discard block |
||
| 71 | 74 | $logger->expects($this->never())->method('error'); |
| 72 | 75 | $class->setLogger($logger); |
| 73 | 76 | |
| 74 | - try { |
|
| 77 | + try |
|
| 78 | + { |
|
| 75 | 79 | $ref->invoke($class, 'foo'); |
| 76 | - } catch (LocatorException) { |
|
| 80 | + } |
|
| 81 | + catch (LocatorException) |
|
| 82 | + { |
|
| 77 | 83 | } |
| 78 | 84 | } |
| 79 | 85 | |
@@ -89,9 +95,12 @@ discard block |
||
| 89 | 95 | ); |
| 90 | 96 | $class->setLogger($logger); |
| 91 | 97 | |
| 92 | - try { |
|
| 98 | + try |
|
| 99 | + { |
|
| 93 | 100 | $ref->invoke($class, 'foo'); |
| 94 | - } catch (LocatorException) { |
|
| 101 | + } |
|
| 102 | + catch (LocatorException) |
|
| 103 | + { |
|
| 95 | 104 | } |
| 96 | 105 | } |
| 97 | 106 | |
@@ -104,14 +113,19 @@ discard block |
||
| 104 | 113 | $logger->expects($this->never())->method('error'); |
| 105 | 114 | $class->setLogger($logger); |
| 106 | 115 | |
| 107 | - try { |
|
| 116 | + try |
|
| 117 | + { |
|
| 108 | 118 | $ref->invoke($class, 'foo'); |
| 109 | - } catch (LocatorException) { |
|
| 119 | + } |
|
| 120 | + catch (LocatorException) |
|
| 121 | + { |
|
| 110 | 122 | } |
| 111 | 123 | } |
| 112 | 124 | |
| 113 | 125 | private function getLocator(bool $debug = false): AbstractLocator |
| 114 | 126 | { |
| 115 | - return new class($this->finder, $debug) extends AbstractLocator {}; |
|
| 127 | + return new class($this->finder, $debug) extends AbstractLocator |
|
| 128 | + { |
|
| 129 | +}; |
|
| 116 | 130 | } |
| 117 | 131 | } |
@@ -37,12 +37,15 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected function availableReflections(): \Generator |
| 39 | 39 | { |
| 40 | - foreach ($this->finder->getIterator() as $file) { |
|
| 40 | + foreach ($this->finder->getIterator() as $file) |
|
| 41 | + { |
|
| 41 | 42 | $reflection = new ReflectionFile((string)$file); |
| 42 | 43 | |
| 43 | - if ($reflection->hasIncludes()) { |
|
| 44 | + if ($reflection->hasIncludes()) |
|
| 45 | + { |
|
| 44 | 46 | // We are not analyzing files which has includes, it's not safe to require such reflections |
| 45 | - if ($this->debug) { |
|
| 47 | + if ($this->debug) |
|
| 48 | + { |
|
| 46 | 49 | $this->getLogger()->warning( |
| 47 | 50 | \sprintf('File `%s` has includes and excluded from analysis', (string) $file), |
| 48 | 51 | ['file' => $file] |
@@ -68,8 +71,10 @@ discard block |
||
| 68 | 71 | */ |
| 69 | 72 | protected function classReflection(string $class): \ReflectionClass |
| 70 | 73 | { |
| 71 | - $loader = static function ($class) { |
|
| 72 | - if ($class === LocatorException::class) { |
|
| 74 | + $loader = static function ($class) |
|
| 75 | + { |
|
| 76 | + if ($class === LocatorException::class) |
|
| 77 | + { |
|
| 73 | 78 | return; |
| 74 | 79 | } |
| 75 | 80 | |
@@ -79,16 +84,21 @@ discard block |
||
| 79 | 84 | //To suspend class dependency exception |
| 80 | 85 | \spl_autoload_register($loader); |
| 81 | 86 | |
| 82 | - try { |
|
| 87 | + try |
|
| 88 | + { |
|
| 83 | 89 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
| 84 | 90 | //we are going to handle such exception and convert it soft exception |
| 85 | 91 | return new \ReflectionClass($class); |
| 86 | - } catch (\Throwable $e) { |
|
| 87 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
| 92 | + } |
|
| 93 | + catch (\Throwable $e) |
|
| 94 | + { |
|
| 95 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
| 96 | + { |
|
| 88 | 97 | $e = $e->getPrevious(); |
| 89 | 98 | } |
| 90 | 99 | |
| 91 | - if ($this->debug) { |
|
| 100 | + if ($this->debug) |
|
| 101 | + { |
|
| 92 | 102 | $this->getLogger()->error( |
| 93 | 103 | \sprintf('%s: %s in %s:%s', $class, $e->getMessage(), $e->getFile(), $e->getLine()), |
| 94 | 104 | ['error' => $e] |
@@ -96,7 +106,9 @@ discard block |
||
| 96 | 106 | } |
| 97 | 107 | |
| 98 | 108 | throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
| 99 | - } finally { |
|
| 109 | + } |
|
| 110 | + finally |
|
| 111 | + { |
|
| 100 | 112 | \spl_autoload_unregister($loader); |
| 101 | 113 | } |
| 102 | 114 | } |
@@ -112,7 +124,8 @@ discard block |
||
| 112 | 124 | protected function enumReflection(string $enum): \ReflectionEnum |
| 113 | 125 | { |
| 114 | 126 | $loader = static function (string $enum): void { |
| 115 | - if ($enum === LocatorException::class) { |
|
| 127 | + if ($enum === LocatorException::class) |
|
| 128 | + { |
|
| 116 | 129 | return; |
| 117 | 130 | } |
| 118 | 131 | |
@@ -122,16 +135,21 @@ discard block |
||
| 122 | 135 | //To suspend class dependency exception |
| 123 | 136 | \spl_autoload_register($loader); |
| 124 | 137 | |
| 125 | - try { |
|
| 138 | + try |
|
| 139 | + { |
|
| 126 | 140 | //In some enum reflection can thrown an exception if enum invalid or can not be loaded, |
| 127 | 141 | //we are going to handle such exception and convert it soft exception |
| 128 | 142 | return new \ReflectionEnum($enum); |
| 129 | - } catch (\Throwable $e) { |
|
| 130 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
| 143 | + } |
|
| 144 | + catch (\Throwable $e) |
|
| 145 | + { |
|
| 146 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
| 147 | + { |
|
| 131 | 148 | $e = $e->getPrevious(); |
| 132 | 149 | } |
| 133 | 150 | |
| 134 | - if ($this->debug) { |
|
| 151 | + if ($this->debug) |
|
| 152 | + { |
|
| 135 | 153 | $this->getLogger()->error( |
| 136 | 154 | \sprintf('%s: %s in %s:%s', $enum, $e->getMessage(), $e->getFile(), $e->getLine()), |
| 137 | 155 | ['error' => $e] |
@@ -139,7 +157,9 @@ discard block |
||
| 139 | 157 | } |
| 140 | 158 | |
| 141 | 159 | throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
| 142 | - } finally { |
|
| 160 | + } |
|
| 161 | + finally |
|
| 162 | + { |
|
| 143 | 163 | \spl_autoload_unregister($loader); |
| 144 | 164 | } |
| 145 | 165 | } |