@@ -40,105 +40,105 @@ discard block |
||
| 40 | 40 | * @return null|string |
| 41 | 41 | */ |
| 42 | 42 | public function getRandom(): ?string { |
| 43 | - return $this->array_rand_value( $this->getUserAgents() ); |
|
| 43 | + return $this->array_rand_value($this->getUserAgents()); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | 49 | public function getAndroid(): array { |
| 50 | - return $this->getUserAgents( 'android' ); |
|
| 50 | + return $this->getUserAgents('android'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @return null|string |
| 55 | 55 | */ |
| 56 | 56 | public function getAndroidRandom(): ?string { |
| 57 | - return $this->array_rand_value( $this->getAndroid() ); |
|
| 57 | + return $this->array_rand_value($this->getAndroid()); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @return array |
| 62 | 62 | */ |
| 63 | 63 | public function getChrome(): array { |
| 64 | - return $this->getUserAgents( 'chrome' ); |
|
| 64 | + return $this->getUserAgents('chrome'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return null|string |
| 69 | 69 | */ |
| 70 | 70 | public function getChromeRandom(): ?string { |
| 71 | - return $this->array_rand_value( $this->getChrome() ); |
|
| 71 | + return $this->array_rand_value($this->getChrome()); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | 77 | public function getEdge(): array { |
| 78 | - return $this->getUserAgents( 'edge' ); |
|
| 78 | + return $this->getUserAgents('edge'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @return null|string |
| 83 | 83 | */ |
| 84 | 84 | public function getEdgeRandom(): ?string { |
| 85 | - return $this->array_rand_value( $this->getEdge() ); |
|
| 85 | + return $this->array_rand_value($this->getEdge()); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | 91 | public function getFirefox(): array { |
| 92 | - return $this->getUserAgents( 'firefox' ); |
|
| 92 | + return $this->getUserAgents('firefox'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @return null|string |
| 97 | 97 | */ |
| 98 | 98 | public function getFirefoxRandom(): ?string { |
| 99 | - return $this->array_rand_value( $this->getFirefox() ); |
|
| 99 | + return $this->array_rand_value($this->getFirefox()); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * @return array |
| 104 | 104 | */ |
| 105 | 105 | public function getInternetExplorer(): array { |
| 106 | - return $this->getUserAgents( 'ie' ); |
|
| 106 | + return $this->getUserAgents('ie'); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * @return null|string |
| 111 | 111 | */ |
| 112 | 112 | public function getInternetExplorerRandom(): ?string { |
| 113 | - return $this->array_rand_value( $this->getInternetExplorer() ); |
|
| 113 | + return $this->array_rand_value($this->getInternetExplorer()); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * @return array |
| 118 | 118 | */ |
| 119 | 119 | public function getOpera(): array { |
| 120 | - return $this->getUserAgents( 'opera' ); |
|
| 120 | + return $this->getUserAgents('opera'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * @return null|string |
| 125 | 125 | */ |
| 126 | 126 | public function getOperaRandom(): ?string { |
| 127 | - return $this->array_rand_value( $this->getOpera() ); |
|
| 127 | + return $this->array_rand_value($this->getOpera()); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | 133 | public function getSafari(): array { |
| 134 | - return $this->getUserAgents( 'safari' ); |
|
| 134 | + return $this->getUserAgents('safari'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * @return null|string |
| 139 | 139 | */ |
| 140 | 140 | public function getSafariRandom(): ?string { |
| 141 | - return $this->array_rand_value( $this->getSafari() ); |
|
| 141 | + return $this->array_rand_value($this->getSafari()); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -146,30 +146,30 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @return array |
| 148 | 148 | */ |
| 149 | - protected function getUserAgents( ?string $lib = null ): array { |
|
| 150 | - if ( ! empty( $lib ) ) { |
|
| 149 | + protected function getUserAgents(?string $lib = null): array { |
|
| 150 | + if ( ! empty($lib)) { |
|
| 151 | 151 | $lib_path = __DIR__ . '/libs/' . $lib . '.txt'; |
| 152 | - $data = file( $lib_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); |
|
| 153 | - if ( ! $data ) { |
|
| 154 | - $data = []; |
|
| 152 | + $data = file($lib_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 153 | + if ( ! $data) { |
|
| 154 | + $data = [ ]; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - return file_exists( $lib_path ) ? $data : []; |
|
| 157 | + return file_exists($lib_path) ? $data : [ ]; |
|
| 158 | 158 | } else { |
| 159 | - $list = []; |
|
| 159 | + $list = [ ]; |
|
| 160 | 160 | // combine all available libs and return it as array |
| 161 | - foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( __DIR__ . '/libs' ) ) as $filename ) { |
|
| 161 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/libs')) as $filename) { |
|
| 162 | 162 | // filter out "." and ".." |
| 163 | - if ( $filename->isDir() ) { |
|
| 163 | + if ($filename->isDir()) { |
|
| 164 | 164 | continue; |
| 165 | 165 | } |
| 166 | - $data = file( $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); |
|
| 167 | - if ( ! $data ) { |
|
| 168 | - $data = []; |
|
| 166 | + $data = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 167 | + if ( ! $data) { |
|
| 168 | + $data = [ ]; |
|
| 169 | 169 | } |
| 170 | - $list = array_merge( $list, $data ); |
|
| 170 | + $list = array_merge($list, $data); |
|
| 171 | 171 | } |
| 172 | - $list = array_values( array_unique( $list ) ); |
|
| 172 | + $list = array_values(array_unique($list)); |
|
| 173 | 173 | |
| 174 | 174 | return $list; |
| 175 | 175 | } |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @return null|string |
| 182 | 182 | */ |
| 183 | - protected function array_rand_value( array $arr ): ?string { |
|
| 184 | - if ( empty( $arr ) ) { |
|
| 183 | + protected function array_rand_value(array $arr): ?string { |
|
| 184 | + if (empty($arr)) { |
|
| 185 | 185 | return null; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - return $arr[ array_rand( $arr ) ]; |
|
| 188 | + return $arr[ array_rand($arr) ]; |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | \ No newline at end of file |