@@ -25,14 +25,14 @@ |
||
| 25 | 25 | namespace OC\DB; |
| 26 | 26 | |
| 27 | 27 | class AdapterPgSql extends Adapter { |
| 28 | - public function lastInsertId($table) { |
|
| 29 | - return $this->conn->fetchColumn('SELECT lastval()'); |
|
| 30 | - } |
|
| 28 | + public function lastInsertId($table) { |
|
| 29 | + return $this->conn->fetchColumn('SELECT lastval()'); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - const UNIX_TIMESTAMP_REPLACEMENT = 'cast(extract(epoch from current_timestamp) as integer)'; |
|
| 33 | - public function fixupStatement($statement) { |
|
| 34 | - $statement = str_replace( '`', '"', $statement ); |
|
| 35 | - $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); |
|
| 36 | - return $statement; |
|
| 37 | - } |
|
| 32 | + const UNIX_TIMESTAMP_REPLACEMENT = 'cast(extract(epoch from current_timestamp) as integer)'; |
|
| 33 | + public function fixupStatement($statement) { |
|
| 34 | + $statement = str_replace( '`', '"', $statement ); |
|
| 35 | + $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); |
|
| 36 | + return $statement; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -31,8 +31,8 @@ |
||
| 31 | 31 | |
| 32 | 32 | const UNIX_TIMESTAMP_REPLACEMENT = 'cast(extract(epoch from current_timestamp) as integer)'; |
| 33 | 33 | public function fixupStatement($statement) { |
| 34 | - $statement = str_replace( '`', '"', $statement ); |
|
| 35 | - $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); |
|
| 34 | + $statement = str_replace('`', '"', $statement); |
|
| 35 | + $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); |
|
| 36 | 36 | return $statement; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -349,8 +349,9 @@ |
||
| 349 | 349 | * @return mixed |
| 350 | 350 | */ |
| 351 | 351 | private function getValue($element) { |
| 352 | - if (isset($element['@value'])) |
|
| 353 | - return $element['@value']; |
|
| 352 | + if (isset($element['@value'])) { |
|
| 353 | + return $element['@value']; |
|
| 354 | + } |
|
| 354 | 355 | return (string)$element; |
| 355 | 356 | } |
| 356 | 357 | } |
@@ -31,319 +31,319 @@ |
||
| 31 | 31 | |
| 32 | 32 | class DependencyAnalyzer { |
| 33 | 33 | |
| 34 | - /** @var Platform */ |
|
| 35 | - private $platform; |
|
| 36 | - /** @var \OCP\IL10N */ |
|
| 37 | - private $l; |
|
| 38 | - /** @var array */ |
|
| 39 | - private $appInfo; |
|
| 34 | + /** @var Platform */ |
|
| 35 | + private $platform; |
|
| 36 | + /** @var \OCP\IL10N */ |
|
| 37 | + private $l; |
|
| 38 | + /** @var array */ |
|
| 39 | + private $appInfo; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param Platform $platform |
|
| 43 | - * @param \OCP\IL10N $l |
|
| 44 | - */ |
|
| 45 | - function __construct(Platform $platform, IL10N $l) { |
|
| 46 | - $this->platform = $platform; |
|
| 47 | - $this->l = $l; |
|
| 48 | - } |
|
| 41 | + /** |
|
| 42 | + * @param Platform $platform |
|
| 43 | + * @param \OCP\IL10N $l |
|
| 44 | + */ |
|
| 45 | + function __construct(Platform $platform, IL10N $l) { |
|
| 46 | + $this->platform = $platform; |
|
| 47 | + $this->l = $l; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param array $app |
|
| 52 | - * @returns array of missing dependencies |
|
| 53 | - */ |
|
| 54 | - public function analyze(array $app) { |
|
| 55 | - $this->appInfo = $app; |
|
| 56 | - if (isset($app['dependencies'])) { |
|
| 57 | - $dependencies = $app['dependencies']; |
|
| 58 | - } else { |
|
| 59 | - $dependencies = []; |
|
| 60 | - } |
|
| 50 | + /** |
|
| 51 | + * @param array $app |
|
| 52 | + * @returns array of missing dependencies |
|
| 53 | + */ |
|
| 54 | + public function analyze(array $app) { |
|
| 55 | + $this->appInfo = $app; |
|
| 56 | + if (isset($app['dependencies'])) { |
|
| 57 | + $dependencies = $app['dependencies']; |
|
| 58 | + } else { |
|
| 59 | + $dependencies = []; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return array_merge( |
|
| 63 | - $this->analyzePhpVersion($dependencies), |
|
| 64 | - $this->analyzeDatabases($dependencies), |
|
| 65 | - $this->analyzeCommands($dependencies), |
|
| 66 | - $this->analyzeLibraries($dependencies), |
|
| 67 | - $this->analyzeOS($dependencies), |
|
| 68 | - $this->analyzeOC($dependencies, $app) |
|
| 69 | - ); |
|
| 70 | - } |
|
| 62 | + return array_merge( |
|
| 63 | + $this->analyzePhpVersion($dependencies), |
|
| 64 | + $this->analyzeDatabases($dependencies), |
|
| 65 | + $this->analyzeCommands($dependencies), |
|
| 66 | + $this->analyzeLibraries($dependencies), |
|
| 67 | + $this->analyzeOS($dependencies), |
|
| 68 | + $this->analyzeOC($dependencies, $app) |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Truncates both versions to the lowest common version, e.g. |
|
| 74 | - * 5.1.2.3 and 5.1 will be turned into 5.1 and 5.1, |
|
| 75 | - * 5.2.6.5 and 5.1 will be turned into 5.2 and 5.1 |
|
| 76 | - * @param string $first |
|
| 77 | - * @param string $second |
|
| 78 | - * @return string[] first element is the first version, second element is the |
|
| 79 | - * second version |
|
| 80 | - */ |
|
| 81 | - private function normalizeVersions($first, $second) { |
|
| 82 | - $first = explode('.', $first); |
|
| 83 | - $second = explode('.', $second); |
|
| 72 | + /** |
|
| 73 | + * Truncates both versions to the lowest common version, e.g. |
|
| 74 | + * 5.1.2.3 and 5.1 will be turned into 5.1 and 5.1, |
|
| 75 | + * 5.2.6.5 and 5.1 will be turned into 5.2 and 5.1 |
|
| 76 | + * @param string $first |
|
| 77 | + * @param string $second |
|
| 78 | + * @return string[] first element is the first version, second element is the |
|
| 79 | + * second version |
|
| 80 | + */ |
|
| 81 | + private function normalizeVersions($first, $second) { |
|
| 82 | + $first = explode('.', $first); |
|
| 83 | + $second = explode('.', $second); |
|
| 84 | 84 | |
| 85 | - // get both arrays to the same minimum size |
|
| 86 | - $length = min(count($second), count($first)); |
|
| 87 | - $first = array_slice($first, 0, $length); |
|
| 88 | - $second = array_slice($second, 0, $length); |
|
| 85 | + // get both arrays to the same minimum size |
|
| 86 | + $length = min(count($second), count($first)); |
|
| 87 | + $first = array_slice($first, 0, $length); |
|
| 88 | + $second = array_slice($second, 0, $length); |
|
| 89 | 89 | |
| 90 | - return [implode('.', $first), implode('.', $second)]; |
|
| 91 | - } |
|
| 90 | + return [implode('.', $first), implode('.', $second)]; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Parameters will be normalized and then passed into version_compare |
|
| 95 | - * in the same order they are specified in the method header |
|
| 96 | - * @param string $first |
|
| 97 | - * @param string $second |
|
| 98 | - * @param string $operator |
|
| 99 | - * @return bool result similar to version_compare |
|
| 100 | - */ |
|
| 101 | - private function compare($first, $second, $operator) { |
|
| 102 | - // we can't normalize versions if one of the given parameters is not a |
|
| 103 | - // version string but null. In case one parameter is null normalization |
|
| 104 | - // will therefore be skipped |
|
| 105 | - if ($first !== null && $second !== null) { |
|
| 106 | - list($first, $second) = $this->normalizeVersions($first, $second); |
|
| 107 | - } |
|
| 93 | + /** |
|
| 94 | + * Parameters will be normalized and then passed into version_compare |
|
| 95 | + * in the same order they are specified in the method header |
|
| 96 | + * @param string $first |
|
| 97 | + * @param string $second |
|
| 98 | + * @param string $operator |
|
| 99 | + * @return bool result similar to version_compare |
|
| 100 | + */ |
|
| 101 | + private function compare($first, $second, $operator) { |
|
| 102 | + // we can't normalize versions if one of the given parameters is not a |
|
| 103 | + // version string but null. In case one parameter is null normalization |
|
| 104 | + // will therefore be skipped |
|
| 105 | + if ($first !== null && $second !== null) { |
|
| 106 | + list($first, $second) = $this->normalizeVersions($first, $second); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return version_compare($first, $second, $operator); |
|
| 110 | - } |
|
| 109 | + return version_compare($first, $second, $operator); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Checks if a version is bigger than another version |
|
| 114 | - * @param string $first |
|
| 115 | - * @param string $second |
|
| 116 | - * @return bool true if the first version is bigger than the second |
|
| 117 | - */ |
|
| 118 | - private function compareBigger($first, $second) { |
|
| 119 | - return $this->compare($first, $second, '>'); |
|
| 120 | - } |
|
| 112 | + /** |
|
| 113 | + * Checks if a version is bigger than another version |
|
| 114 | + * @param string $first |
|
| 115 | + * @param string $second |
|
| 116 | + * @return bool true if the first version is bigger than the second |
|
| 117 | + */ |
|
| 118 | + private function compareBigger($first, $second) { |
|
| 119 | + return $this->compare($first, $second, '>'); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Checks if a version is smaller than another version |
|
| 124 | - * @param string $first |
|
| 125 | - * @param string $second |
|
| 126 | - * @return bool true if the first version is smaller than the second |
|
| 127 | - */ |
|
| 128 | - private function compareSmaller($first, $second) { |
|
| 129 | - return $this->compare($first, $second, '<'); |
|
| 130 | - } |
|
| 122 | + /** |
|
| 123 | + * Checks if a version is smaller than another version |
|
| 124 | + * @param string $first |
|
| 125 | + * @param string $second |
|
| 126 | + * @return bool true if the first version is smaller than the second |
|
| 127 | + */ |
|
| 128 | + private function compareSmaller($first, $second) { |
|
| 129 | + return $this->compare($first, $second, '<'); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @param array $dependencies |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - private function analyzePhpVersion(array $dependencies) { |
|
| 137 | - $missing = []; |
|
| 138 | - if (isset($dependencies['php']['@attributes']['min-version'])) { |
|
| 139 | - $minVersion = $dependencies['php']['@attributes']['min-version']; |
|
| 140 | - if ($this->compareSmaller($this->platform->getPhpVersion(), $minVersion)) { |
|
| 141 | - $missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - if (isset($dependencies['php']['@attributes']['max-version'])) { |
|
| 145 | - $maxVersion = $dependencies['php']['@attributes']['max-version']; |
|
| 146 | - if ($this->compareBigger($this->platform->getPhpVersion(), $maxVersion)) { |
|
| 147 | - $missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if (isset($dependencies['php']['@attributes']['min-int-size'])) { |
|
| 151 | - $intSize = $dependencies['php']['@attributes']['min-int-size']; |
|
| 152 | - if ($intSize > $this->platform->getIntSize()*8) { |
|
| 153 | - $missing[] = (string)$this->l->t('%sbit or higher PHP required.', $intSize); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - return $missing; |
|
| 157 | - } |
|
| 132 | + /** |
|
| 133 | + * @param array $dependencies |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + private function analyzePhpVersion(array $dependencies) { |
|
| 137 | + $missing = []; |
|
| 138 | + if (isset($dependencies['php']['@attributes']['min-version'])) { |
|
| 139 | + $minVersion = $dependencies['php']['@attributes']['min-version']; |
|
| 140 | + if ($this->compareSmaller($this->platform->getPhpVersion(), $minVersion)) { |
|
| 141 | + $missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + if (isset($dependencies['php']['@attributes']['max-version'])) { |
|
| 145 | + $maxVersion = $dependencies['php']['@attributes']['max-version']; |
|
| 146 | + if ($this->compareBigger($this->platform->getPhpVersion(), $maxVersion)) { |
|
| 147 | + $missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if (isset($dependencies['php']['@attributes']['min-int-size'])) { |
|
| 151 | + $intSize = $dependencies['php']['@attributes']['min-int-size']; |
|
| 152 | + if ($intSize > $this->platform->getIntSize()*8) { |
|
| 153 | + $missing[] = (string)$this->l->t('%sbit or higher PHP required.', $intSize); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + return $missing; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @param array $dependencies |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - private function analyzeDatabases(array $dependencies) { |
|
| 164 | - $missing = []; |
|
| 165 | - if (!isset($dependencies['database'])) { |
|
| 166 | - return $missing; |
|
| 167 | - } |
|
| 159 | + /** |
|
| 160 | + * @param array $dependencies |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + private function analyzeDatabases(array $dependencies) { |
|
| 164 | + $missing = []; |
|
| 165 | + if (!isset($dependencies['database'])) { |
|
| 166 | + return $missing; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - $supportedDatabases = $dependencies['database']; |
|
| 170 | - if (empty($supportedDatabases)) { |
|
| 171 | - return $missing; |
|
| 172 | - } |
|
| 173 | - if (!is_array($supportedDatabases)) { |
|
| 174 | - $supportedDatabases = array($supportedDatabases); |
|
| 175 | - } |
|
| 176 | - $supportedDatabases = array_map(function ($db) { |
|
| 177 | - return $this->getValue($db); |
|
| 178 | - }, $supportedDatabases); |
|
| 179 | - $currentDatabase = $this->platform->getDatabase(); |
|
| 180 | - if (!in_array($currentDatabase, $supportedDatabases)) { |
|
| 181 | - $missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); |
|
| 182 | - } |
|
| 183 | - return $missing; |
|
| 184 | - } |
|
| 169 | + $supportedDatabases = $dependencies['database']; |
|
| 170 | + if (empty($supportedDatabases)) { |
|
| 171 | + return $missing; |
|
| 172 | + } |
|
| 173 | + if (!is_array($supportedDatabases)) { |
|
| 174 | + $supportedDatabases = array($supportedDatabases); |
|
| 175 | + } |
|
| 176 | + $supportedDatabases = array_map(function ($db) { |
|
| 177 | + return $this->getValue($db); |
|
| 178 | + }, $supportedDatabases); |
|
| 179 | + $currentDatabase = $this->platform->getDatabase(); |
|
| 180 | + if (!in_array($currentDatabase, $supportedDatabases)) { |
|
| 181 | + $missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); |
|
| 182 | + } |
|
| 183 | + return $missing; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * @param array $dependencies |
|
| 188 | - * @return array |
|
| 189 | - */ |
|
| 190 | - private function analyzeCommands(array $dependencies) { |
|
| 191 | - $missing = []; |
|
| 192 | - if (!isset($dependencies['command'])) { |
|
| 193 | - return $missing; |
|
| 194 | - } |
|
| 186 | + /** |
|
| 187 | + * @param array $dependencies |
|
| 188 | + * @return array |
|
| 189 | + */ |
|
| 190 | + private function analyzeCommands(array $dependencies) { |
|
| 191 | + $missing = []; |
|
| 192 | + if (!isset($dependencies['command'])) { |
|
| 193 | + return $missing; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - $commands = $dependencies['command']; |
|
| 197 | - if (!is_array($commands)) { |
|
| 198 | - $commands = array($commands); |
|
| 199 | - } |
|
| 200 | - $os = $this->platform->getOS(); |
|
| 201 | - foreach ($commands as $command) { |
|
| 202 | - if (isset($command['@attributes']['os']) && $command['@attributes']['os'] !== $os) { |
|
| 203 | - continue; |
|
| 204 | - } |
|
| 205 | - $commandName = $this->getValue($command); |
|
| 206 | - if (!$this->platform->isCommandKnown($commandName)) { |
|
| 207 | - $missing[] = (string)$this->l->t('The command line tool %s could not be found', $commandName); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - return $missing; |
|
| 211 | - } |
|
| 196 | + $commands = $dependencies['command']; |
|
| 197 | + if (!is_array($commands)) { |
|
| 198 | + $commands = array($commands); |
|
| 199 | + } |
|
| 200 | + $os = $this->platform->getOS(); |
|
| 201 | + foreach ($commands as $command) { |
|
| 202 | + if (isset($command['@attributes']['os']) && $command['@attributes']['os'] !== $os) { |
|
| 203 | + continue; |
|
| 204 | + } |
|
| 205 | + $commandName = $this->getValue($command); |
|
| 206 | + if (!$this->platform->isCommandKnown($commandName)) { |
|
| 207 | + $missing[] = (string)$this->l->t('The command line tool %s could not be found', $commandName); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + return $missing; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * @param array $dependencies |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - private function analyzeLibraries(array $dependencies) { |
|
| 218 | - $missing = []; |
|
| 219 | - if (!isset($dependencies['lib'])) { |
|
| 220 | - return $missing; |
|
| 221 | - } |
|
| 213 | + /** |
|
| 214 | + * @param array $dependencies |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + private function analyzeLibraries(array $dependencies) { |
|
| 218 | + $missing = []; |
|
| 219 | + if (!isset($dependencies['lib'])) { |
|
| 220 | + return $missing; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - $libs = $dependencies['lib']; |
|
| 224 | - if (!is_array($libs)) { |
|
| 225 | - $libs = array($libs); |
|
| 226 | - } |
|
| 227 | - foreach ($libs as $lib) { |
|
| 228 | - $libName = $this->getValue($lib); |
|
| 229 | - $libVersion = $this->platform->getLibraryVersion($libName); |
|
| 230 | - if (is_null($libVersion)) { |
|
| 231 | - $missing[] = (string)$this->l->t('The library %s is not available.', $libName); |
|
| 232 | - continue; |
|
| 233 | - } |
|
| 223 | + $libs = $dependencies['lib']; |
|
| 224 | + if (!is_array($libs)) { |
|
| 225 | + $libs = array($libs); |
|
| 226 | + } |
|
| 227 | + foreach ($libs as $lib) { |
|
| 228 | + $libName = $this->getValue($lib); |
|
| 229 | + $libVersion = $this->platform->getLibraryVersion($libName); |
|
| 230 | + if (is_null($libVersion)) { |
|
| 231 | + $missing[] = (string)$this->l->t('The library %s is not available.', $libName); |
|
| 232 | + continue; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - if (is_array($lib)) { |
|
| 236 | - if (isset($lib['@attributes']['min-version'])) { |
|
| 237 | - $minVersion = $lib['@attributes']['min-version']; |
|
| 238 | - if ($this->compareSmaller($libVersion, $minVersion)) { |
|
| 239 | - $missing[] = (string)$this->l->t('Library %s with a version higher than %s is required - available version %s.', |
|
| 240 | - array($libName, $minVersion, $libVersion)); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - if (isset($lib['@attributes']['max-version'])) { |
|
| 244 | - $maxVersion = $lib['@attributes']['max-version']; |
|
| 245 | - if ($this->compareBigger($libVersion, $maxVersion)) { |
|
| 246 | - $missing[] = (string)$this->l->t('Library %s with a version lower than %s is required - available version %s.', |
|
| 247 | - array($libName, $maxVersion, $libVersion)); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - return $missing; |
|
| 253 | - } |
|
| 235 | + if (is_array($lib)) { |
|
| 236 | + if (isset($lib['@attributes']['min-version'])) { |
|
| 237 | + $minVersion = $lib['@attributes']['min-version']; |
|
| 238 | + if ($this->compareSmaller($libVersion, $minVersion)) { |
|
| 239 | + $missing[] = (string)$this->l->t('Library %s with a version higher than %s is required - available version %s.', |
|
| 240 | + array($libName, $minVersion, $libVersion)); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + if (isset($lib['@attributes']['max-version'])) { |
|
| 244 | + $maxVersion = $lib['@attributes']['max-version']; |
|
| 245 | + if ($this->compareBigger($libVersion, $maxVersion)) { |
|
| 246 | + $missing[] = (string)$this->l->t('Library %s with a version lower than %s is required - available version %s.', |
|
| 247 | + array($libName, $maxVersion, $libVersion)); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + return $missing; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @param array $dependencies |
|
| 257 | - * @return array |
|
| 258 | - */ |
|
| 259 | - private function analyzeOS(array $dependencies) { |
|
| 260 | - $missing = []; |
|
| 261 | - if (!isset($dependencies['os'])) { |
|
| 262 | - return $missing; |
|
| 263 | - } |
|
| 255 | + /** |
|
| 256 | + * @param array $dependencies |
|
| 257 | + * @return array |
|
| 258 | + */ |
|
| 259 | + private function analyzeOS(array $dependencies) { |
|
| 260 | + $missing = []; |
|
| 261 | + if (!isset($dependencies['os'])) { |
|
| 262 | + return $missing; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - $oss = $dependencies['os']; |
|
| 266 | - if (empty($oss)) { |
|
| 267 | - return $missing; |
|
| 268 | - } |
|
| 269 | - if (is_array($oss)) { |
|
| 270 | - $oss = array_map(function ($os) { |
|
| 271 | - return $this->getValue($os); |
|
| 272 | - }, $oss); |
|
| 273 | - } else { |
|
| 274 | - $oss = array($oss); |
|
| 275 | - } |
|
| 276 | - $currentOS = $this->platform->getOS(); |
|
| 277 | - if (!in_array($currentOS, $oss)) { |
|
| 278 | - $missing[] = (string)$this->l->t('Following platforms are supported: %s', join(', ', $oss)); |
|
| 279 | - } |
|
| 280 | - return $missing; |
|
| 281 | - } |
|
| 265 | + $oss = $dependencies['os']; |
|
| 266 | + if (empty($oss)) { |
|
| 267 | + return $missing; |
|
| 268 | + } |
|
| 269 | + if (is_array($oss)) { |
|
| 270 | + $oss = array_map(function ($os) { |
|
| 271 | + return $this->getValue($os); |
|
| 272 | + }, $oss); |
|
| 273 | + } else { |
|
| 274 | + $oss = array($oss); |
|
| 275 | + } |
|
| 276 | + $currentOS = $this->platform->getOS(); |
|
| 277 | + if (!in_array($currentOS, $oss)) { |
|
| 278 | + $missing[] = (string)$this->l->t('Following platforms are supported: %s', join(', ', $oss)); |
|
| 279 | + } |
|
| 280 | + return $missing; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * @param array $dependencies |
|
| 285 | - * @param array $appInfo |
|
| 286 | - * @return array |
|
| 287 | - */ |
|
| 288 | - private function analyzeOC(array $dependencies, array $appInfo) { |
|
| 289 | - $missing = []; |
|
| 290 | - $minVersion = null; |
|
| 291 | - if (isset($dependencies['owncloud']['@attributes']['min-version'])) { |
|
| 292 | - $minVersion = $dependencies['owncloud']['@attributes']['min-version']; |
|
| 293 | - } elseif (isset($appInfo['requiremin'])) { |
|
| 294 | - $minVersion = $appInfo['requiremin']; |
|
| 295 | - } elseif (isset($appInfo['require'])) { |
|
| 296 | - $minVersion = $appInfo['require']; |
|
| 297 | - } |
|
| 298 | - $maxVersion = null; |
|
| 299 | - if (isset($dependencies['owncloud']['@attributes']['max-version'])) { |
|
| 300 | - $maxVersion = $dependencies['owncloud']['@attributes']['max-version']; |
|
| 301 | - } elseif (isset($appInfo['requiremax'])) { |
|
| 302 | - $maxVersion = $appInfo['requiremax']; |
|
| 303 | - } |
|
| 283 | + /** |
|
| 284 | + * @param array $dependencies |
|
| 285 | + * @param array $appInfo |
|
| 286 | + * @return array |
|
| 287 | + */ |
|
| 288 | + private function analyzeOC(array $dependencies, array $appInfo) { |
|
| 289 | + $missing = []; |
|
| 290 | + $minVersion = null; |
|
| 291 | + if (isset($dependencies['owncloud']['@attributes']['min-version'])) { |
|
| 292 | + $minVersion = $dependencies['owncloud']['@attributes']['min-version']; |
|
| 293 | + } elseif (isset($appInfo['requiremin'])) { |
|
| 294 | + $minVersion = $appInfo['requiremin']; |
|
| 295 | + } elseif (isset($appInfo['require'])) { |
|
| 296 | + $minVersion = $appInfo['require']; |
|
| 297 | + } |
|
| 298 | + $maxVersion = null; |
|
| 299 | + if (isset($dependencies['owncloud']['@attributes']['max-version'])) { |
|
| 300 | + $maxVersion = $dependencies['owncloud']['@attributes']['max-version']; |
|
| 301 | + } elseif (isset($appInfo['requiremax'])) { |
|
| 302 | + $maxVersion = $appInfo['requiremax']; |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - if (!is_null($minVersion)) { |
|
| 306 | - if ($this->compareSmaller($this->platform->getOcVersion(), $minVersion)) { |
|
| 307 | - $missing[] = (string)$this->l->t('Server version %s or higher is required.', $this->toVisibleVersion($minVersion)); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - if (!is_null($maxVersion)) { |
|
| 311 | - if ($this->compareBigger($this->platform->getOcVersion(), $maxVersion)) { |
|
| 312 | - $missing[] = (string)$this->l->t('Server version %s or lower is required.', $this->toVisibleVersion($maxVersion)); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - return $missing; |
|
| 316 | - } |
|
| 305 | + if (!is_null($minVersion)) { |
|
| 306 | + if ($this->compareSmaller($this->platform->getOcVersion(), $minVersion)) { |
|
| 307 | + $missing[] = (string)$this->l->t('Server version %s or higher is required.', $this->toVisibleVersion($minVersion)); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + if (!is_null($maxVersion)) { |
|
| 311 | + if ($this->compareBigger($this->platform->getOcVersion(), $maxVersion)) { |
|
| 312 | + $missing[] = (string)$this->l->t('Server version %s or lower is required.', $this->toVisibleVersion($maxVersion)); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + return $missing; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * Map the internal version number to the Nextcloud version |
|
| 320 | - * |
|
| 321 | - * @param string $version |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 324 | - protected function toVisibleVersion($version) { |
|
| 325 | - switch ($version) { |
|
| 326 | - case '9.1': |
|
| 327 | - return '10'; |
|
| 328 | - case '9.2': |
|
| 329 | - return '11'; |
|
| 330 | - default: |
|
| 331 | - if (strpos($version, '9.1.') === 0) { |
|
| 332 | - $version = '10.0.' . substr($version, 4); |
|
| 333 | - } else if (strpos($version, '9.2.') === 0) { |
|
| 334 | - $version = '11.0.' . substr($version, 4); |
|
| 335 | - } |
|
| 336 | - return $version; |
|
| 337 | - } |
|
| 338 | - } |
|
| 318 | + /** |
|
| 319 | + * Map the internal version number to the Nextcloud version |
|
| 320 | + * |
|
| 321 | + * @param string $version |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | + protected function toVisibleVersion($version) { |
|
| 325 | + switch ($version) { |
|
| 326 | + case '9.1': |
|
| 327 | + return '10'; |
|
| 328 | + case '9.2': |
|
| 329 | + return '11'; |
|
| 330 | + default: |
|
| 331 | + if (strpos($version, '9.1.') === 0) { |
|
| 332 | + $version = '10.0.' . substr($version, 4); |
|
| 333 | + } else if (strpos($version, '9.2.') === 0) { |
|
| 334 | + $version = '11.0.' . substr($version, 4); |
|
| 335 | + } |
|
| 336 | + return $version; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * @param $element |
|
| 342 | - * @return mixed |
|
| 343 | - */ |
|
| 344 | - private function getValue($element) { |
|
| 345 | - if (isset($element['@value'])) |
|
| 346 | - return $element['@value']; |
|
| 347 | - return (string)$element; |
|
| 348 | - } |
|
| 340 | + /** |
|
| 341 | + * @param $element |
|
| 342 | + * @return mixed |
|
| 343 | + */ |
|
| 344 | + private function getValue($element) { |
|
| 345 | + if (isset($element['@value'])) |
|
| 346 | + return $element['@value']; |
|
| 347 | + return (string)$element; |
|
| 348 | + } |
|
| 349 | 349 | } |
@@ -138,19 +138,19 @@ discard block |
||
| 138 | 138 | if (isset($dependencies['php']['@attributes']['min-version'])) { |
| 139 | 139 | $minVersion = $dependencies['php']['@attributes']['min-version']; |
| 140 | 140 | if ($this->compareSmaller($this->platform->getPhpVersion(), $minVersion)) { |
| 141 | - $missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); |
|
| 141 | + $missing[] = (string) $this->l->t('PHP %s or higher is required.', $minVersion); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | if (isset($dependencies['php']['@attributes']['max-version'])) { |
| 145 | 145 | $maxVersion = $dependencies['php']['@attributes']['max-version']; |
| 146 | 146 | if ($this->compareBigger($this->platform->getPhpVersion(), $maxVersion)) { |
| 147 | - $missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion); |
|
| 147 | + $missing[] = (string) $this->l->t('PHP with a version lower than %s is required.', $maxVersion); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | if (isset($dependencies['php']['@attributes']['min-int-size'])) { |
| 151 | 151 | $intSize = $dependencies['php']['@attributes']['min-int-size']; |
| 152 | - if ($intSize > $this->platform->getIntSize()*8) { |
|
| 153 | - $missing[] = (string)$this->l->t('%sbit or higher PHP required.', $intSize); |
|
| 152 | + if ($intSize > $this->platform->getIntSize() * 8) { |
|
| 153 | + $missing[] = (string) $this->l->t('%sbit or higher PHP required.', $intSize); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | return $missing; |
@@ -173,12 +173,12 @@ discard block |
||
| 173 | 173 | if (!is_array($supportedDatabases)) { |
| 174 | 174 | $supportedDatabases = array($supportedDatabases); |
| 175 | 175 | } |
| 176 | - $supportedDatabases = array_map(function ($db) { |
|
| 176 | + $supportedDatabases = array_map(function($db) { |
|
| 177 | 177 | return $this->getValue($db); |
| 178 | 178 | }, $supportedDatabases); |
| 179 | 179 | $currentDatabase = $this->platform->getDatabase(); |
| 180 | 180 | if (!in_array($currentDatabase, $supportedDatabases)) { |
| 181 | - $missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); |
|
| 181 | + $missing[] = (string) $this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); |
|
| 182 | 182 | } |
| 183 | 183 | return $missing; |
| 184 | 184 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | $commandName = $this->getValue($command); |
| 206 | 206 | if (!$this->platform->isCommandKnown($commandName)) { |
| 207 | - $missing[] = (string)$this->l->t('The command line tool %s could not be found', $commandName); |
|
| 207 | + $missing[] = (string) $this->l->t('The command line tool %s could not be found', $commandName); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | return $missing; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $libName = $this->getValue($lib); |
| 229 | 229 | $libVersion = $this->platform->getLibraryVersion($libName); |
| 230 | 230 | if (is_null($libVersion)) { |
| 231 | - $missing[] = (string)$this->l->t('The library %s is not available.', $libName); |
|
| 231 | + $missing[] = (string) $this->l->t('The library %s is not available.', $libName); |
|
| 232 | 232 | continue; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | if (isset($lib['@attributes']['min-version'])) { |
| 237 | 237 | $minVersion = $lib['@attributes']['min-version']; |
| 238 | 238 | if ($this->compareSmaller($libVersion, $minVersion)) { |
| 239 | - $missing[] = (string)$this->l->t('Library %s with a version higher than %s is required - available version %s.', |
|
| 239 | + $missing[] = (string) $this->l->t('Library %s with a version higher than %s is required - available version %s.', |
|
| 240 | 240 | array($libName, $minVersion, $libVersion)); |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | if (isset($lib['@attributes']['max-version'])) { |
| 244 | 244 | $maxVersion = $lib['@attributes']['max-version']; |
| 245 | 245 | if ($this->compareBigger($libVersion, $maxVersion)) { |
| 246 | - $missing[] = (string)$this->l->t('Library %s with a version lower than %s is required - available version %s.', |
|
| 246 | + $missing[] = (string) $this->l->t('Library %s with a version lower than %s is required - available version %s.', |
|
| 247 | 247 | array($libName, $maxVersion, $libVersion)); |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | return $missing; |
| 268 | 268 | } |
| 269 | 269 | if (is_array($oss)) { |
| 270 | - $oss = array_map(function ($os) { |
|
| 270 | + $oss = array_map(function($os) { |
|
| 271 | 271 | return $this->getValue($os); |
| 272 | 272 | }, $oss); |
| 273 | 273 | } else { |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | $currentOS = $this->platform->getOS(); |
| 277 | 277 | if (!in_array($currentOS, $oss)) { |
| 278 | - $missing[] = (string)$this->l->t('Following platforms are supported: %s', join(', ', $oss)); |
|
| 278 | + $missing[] = (string) $this->l->t('Following platforms are supported: %s', join(', ', $oss)); |
|
| 279 | 279 | } |
| 280 | 280 | return $missing; |
| 281 | 281 | } |
@@ -304,12 +304,12 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | if (!is_null($minVersion)) { |
| 306 | 306 | if ($this->compareSmaller($this->platform->getOcVersion(), $minVersion)) { |
| 307 | - $missing[] = (string)$this->l->t('Server version %s or higher is required.', $this->toVisibleVersion($minVersion)); |
|
| 307 | + $missing[] = (string) $this->l->t('Server version %s or higher is required.', $this->toVisibleVersion($minVersion)); |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | if (!is_null($maxVersion)) { |
| 311 | 311 | if ($this->compareBigger($this->platform->getOcVersion(), $maxVersion)) { |
| 312 | - $missing[] = (string)$this->l->t('Server version %s or lower is required.', $this->toVisibleVersion($maxVersion)); |
|
| 312 | + $missing[] = (string) $this->l->t('Server version %s or lower is required.', $this->toVisibleVersion($maxVersion)); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | return $missing; |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | return '11'; |
| 330 | 330 | default: |
| 331 | 331 | if (strpos($version, '9.1.') === 0) { |
| 332 | - $version = '10.0.' . substr($version, 4); |
|
| 332 | + $version = '10.0.'.substr($version, 4); |
|
| 333 | 333 | } else if (strpos($version, '9.2.') === 0) { |
| 334 | - $version = '11.0.' . substr($version, 4); |
|
| 334 | + $version = '11.0.'.substr($version, 4); |
|
| 335 | 335 | } |
| 336 | 336 | return $version; |
| 337 | 337 | } |
@@ -344,6 +344,6 @@ discard block |
||
| 344 | 344 | private function getValue($element) { |
| 345 | 345 | if (isset($element['@value'])) |
| 346 | 346 | return $element['@value']; |
| 347 | - return (string)$element; |
|
| 347 | + return (string) $element; |
|
| 348 | 348 | } |
| 349 | 349 | } |
@@ -23,118 +23,118 @@ |
||
| 23 | 23 | namespace OC\App\CodeChecker; |
| 24 | 24 | |
| 25 | 25 | abstract class AbstractCheck implements ICheck { |
| 26 | - /** @var ICheck */ |
|
| 27 | - protected $check; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param ICheck $check |
|
| 31 | - */ |
|
| 32 | - public function __construct(ICheck $check) { |
|
| 33 | - $this->check = $check; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param int $errorCode |
|
| 38 | - * @param string $errorObject |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function getDescription($errorCode, $errorObject) { |
|
| 42 | - switch ($errorCode) { |
|
| 43 | - case CodeChecker::STATIC_CALL_NOT_ALLOWED: |
|
| 44 | - $functions = $this->getLocalFunctions(); |
|
| 45 | - $functions = array_change_key_case($functions, CASE_LOWER); |
|
| 46 | - if (isset($functions[$errorObject])) { |
|
| 47 | - return $this->getLocalDescription(); |
|
| 48 | - } |
|
| 49 | - // no break; |
|
| 50 | - case CodeChecker::CLASS_EXTENDS_NOT_ALLOWED: |
|
| 51 | - case CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED: |
|
| 52 | - case CodeChecker::CLASS_NEW_NOT_ALLOWED: |
|
| 53 | - case CodeChecker::CLASS_USE_NOT_ALLOWED: |
|
| 54 | - $classes = $this->getLocalClasses(); |
|
| 55 | - $classes = array_change_key_case($classes, CASE_LOWER); |
|
| 56 | - if (isset($classes[$errorObject])) { |
|
| 57 | - return $this->getLocalDescription(); |
|
| 58 | - } |
|
| 59 | - break; |
|
| 60 | - |
|
| 61 | - case CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED: |
|
| 62 | - $constants = $this->getLocalConstants(); |
|
| 63 | - $constants = array_change_key_case($constants, CASE_LOWER); |
|
| 64 | - if (isset($constants[$errorObject])) { |
|
| 65 | - return $this->getLocalDescription(); |
|
| 66 | - } |
|
| 67 | - break; |
|
| 68 | - |
|
| 69 | - case CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED: |
|
| 70 | - $methods = $this->getLocalMethods(); |
|
| 71 | - $methods = array_change_key_case($methods, CASE_LOWER); |
|
| 72 | - if (isset($methods[$errorObject])) { |
|
| 73 | - return $this->getLocalDescription(); |
|
| 74 | - } |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - return $this->check->getDescription($errorCode, $errorObject); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - abstract protected function getLocalDescription(); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - abstract protected function getLocalClasses(); |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - abstract protected function getLocalConstants(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - abstract protected function getLocalFunctions(); |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - abstract protected function getLocalMethods(); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return array E.g.: `'ClassName' => 'oc version',` |
|
| 108 | - */ |
|
| 109 | - public function getClasses() { |
|
| 110 | - return array_merge($this->getLocalClasses(), $this->check->getClasses()); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
| 115 | - */ |
|
| 116 | - public function getConstants() { |
|
| 117 | - return array_merge($this->getLocalConstants(), $this->check->getConstants()); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return array E.g.: `'functionName' => 'oc version',` |
|
| 122 | - */ |
|
| 123 | - public function getFunctions() { |
|
| 124 | - return array_merge($this->getLocalFunctions(), $this->check->getFunctions()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
| 129 | - */ |
|
| 130 | - public function getMethods() { |
|
| 131 | - return array_merge($this->getLocalMethods(), $this->check->getMethods()); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function checkStrongComparisons() { |
|
| 138 | - return $this->check->checkStrongComparisons(); |
|
| 139 | - } |
|
| 26 | + /** @var ICheck */ |
|
| 27 | + protected $check; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param ICheck $check |
|
| 31 | + */ |
|
| 32 | + public function __construct(ICheck $check) { |
|
| 33 | + $this->check = $check; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param int $errorCode |
|
| 38 | + * @param string $errorObject |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function getDescription($errorCode, $errorObject) { |
|
| 42 | + switch ($errorCode) { |
|
| 43 | + case CodeChecker::STATIC_CALL_NOT_ALLOWED: |
|
| 44 | + $functions = $this->getLocalFunctions(); |
|
| 45 | + $functions = array_change_key_case($functions, CASE_LOWER); |
|
| 46 | + if (isset($functions[$errorObject])) { |
|
| 47 | + return $this->getLocalDescription(); |
|
| 48 | + } |
|
| 49 | + // no break; |
|
| 50 | + case CodeChecker::CLASS_EXTENDS_NOT_ALLOWED: |
|
| 51 | + case CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED: |
|
| 52 | + case CodeChecker::CLASS_NEW_NOT_ALLOWED: |
|
| 53 | + case CodeChecker::CLASS_USE_NOT_ALLOWED: |
|
| 54 | + $classes = $this->getLocalClasses(); |
|
| 55 | + $classes = array_change_key_case($classes, CASE_LOWER); |
|
| 56 | + if (isset($classes[$errorObject])) { |
|
| 57 | + return $this->getLocalDescription(); |
|
| 58 | + } |
|
| 59 | + break; |
|
| 60 | + |
|
| 61 | + case CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED: |
|
| 62 | + $constants = $this->getLocalConstants(); |
|
| 63 | + $constants = array_change_key_case($constants, CASE_LOWER); |
|
| 64 | + if (isset($constants[$errorObject])) { |
|
| 65 | + return $this->getLocalDescription(); |
|
| 66 | + } |
|
| 67 | + break; |
|
| 68 | + |
|
| 69 | + case CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED: |
|
| 70 | + $methods = $this->getLocalMethods(); |
|
| 71 | + $methods = array_change_key_case($methods, CASE_LOWER); |
|
| 72 | + if (isset($methods[$errorObject])) { |
|
| 73 | + return $this->getLocalDescription(); |
|
| 74 | + } |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + return $this->check->getDescription($errorCode, $errorObject); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + abstract protected function getLocalDescription(); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + abstract protected function getLocalClasses(); |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + abstract protected function getLocalConstants(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + abstract protected function getLocalFunctions(); |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + abstract protected function getLocalMethods(); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return array E.g.: `'ClassName' => 'oc version',` |
|
| 108 | + */ |
|
| 109 | + public function getClasses() { |
|
| 110 | + return array_merge($this->getLocalClasses(), $this->check->getClasses()); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
| 115 | + */ |
|
| 116 | + public function getConstants() { |
|
| 117 | + return array_merge($this->getLocalConstants(), $this->check->getConstants()); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return array E.g.: `'functionName' => 'oc version',` |
|
| 122 | + */ |
|
| 123 | + public function getFunctions() { |
|
| 124 | + return array_merge($this->getLocalFunctions(), $this->check->getFunctions()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
| 129 | + */ |
|
| 130 | + public function getMethods() { |
|
| 131 | + return array_merge($this->getLocalMethods(), $this->check->getMethods()); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function checkStrongComparisons() { |
|
| 138 | + return $this->check->checkStrongComparisons(); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -22,47 +22,47 @@ |
||
| 22 | 22 | namespace OC\App\CodeChecker; |
| 23 | 23 | |
| 24 | 24 | class EmptyCheck implements ICheck { |
| 25 | - /** |
|
| 26 | - * @param int $errorCode |
|
| 27 | - * @param string $errorObject |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getDescription($errorCode, $errorObject) { |
|
| 31 | - return ''; |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param int $errorCode |
|
| 27 | + * @param string $errorObject |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getDescription($errorCode, $errorObject) { |
|
| 31 | + return ''; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return array E.g.: `'ClassName' => 'oc version',` |
|
| 36 | - */ |
|
| 37 | - public function getClasses() { |
|
| 38 | - return []; |
|
| 39 | - } |
|
| 34 | + /** |
|
| 35 | + * @return array E.g.: `'ClassName' => 'oc version',` |
|
| 36 | + */ |
|
| 37 | + public function getClasses() { |
|
| 38 | + return []; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
| 43 | - */ |
|
| 44 | - public function getConstants() { |
|
| 45 | - return []; |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
| 43 | + */ |
|
| 44 | + public function getConstants() { |
|
| 45 | + return []; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return array E.g.: `'functionName' => 'oc version',` |
|
| 50 | - */ |
|
| 51 | - public function getFunctions() { |
|
| 52 | - return []; |
|
| 53 | - } |
|
| 48 | + /** |
|
| 49 | + * @return array E.g.: `'functionName' => 'oc version',` |
|
| 50 | + */ |
|
| 51 | + public function getFunctions() { |
|
| 52 | + return []; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
| 57 | - */ |
|
| 58 | - public function getMethods() { |
|
| 59 | - return []; |
|
| 60 | - } |
|
| 55 | + /** |
|
| 56 | + * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
| 57 | + */ |
|
| 58 | + public function getMethods() { |
|
| 59 | + return []; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - public function checkStrongComparisons() { |
|
| 66 | - return false; |
|
| 67 | - } |
|
| 62 | + /** |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + public function checkStrongComparisons() { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -23,63 +23,63 @@ |
||
| 23 | 23 | namespace OC\App\CodeChecker; |
| 24 | 24 | |
| 25 | 25 | class PrivateCheck extends AbstractCheck implements ICheck { |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - protected function getLocalDescription() { |
|
| 30 | - return 'private'; |
|
| 31 | - } |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + protected function getLocalDescription() { |
|
| 30 | + return 'private'; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return array |
|
| 35 | - */ |
|
| 36 | - public function getLocalClasses() { |
|
| 37 | - return [ |
|
| 38 | - // classes replaced by the public api |
|
| 39 | - 'OC_API' => '6.0.0', |
|
| 40 | - 'OC_App' => '6.0.0', |
|
| 41 | - 'OC_AppConfig' => '6.0.0', |
|
| 42 | - 'OC_Avatar' => '6.0.0', |
|
| 43 | - 'OC_BackgroundJob' => '6.0.0', |
|
| 44 | - 'OC_Config' => '6.0.0', |
|
| 45 | - 'OC_DB' => '6.0.0', |
|
| 46 | - 'OC_Files' => '6.0.0', |
|
| 47 | - 'OC_Helper' => '6.0.0', |
|
| 48 | - 'OC_Hook' => '6.0.0', |
|
| 49 | - 'OC_Image' => '6.0.0', |
|
| 50 | - 'OC_JSON' => '6.0.0', |
|
| 51 | - 'OC_L10N' => '6.0.0', |
|
| 52 | - 'OC_Log' => '6.0.0', |
|
| 53 | - 'OC_Mail' => '6.0.0', |
|
| 54 | - 'OC_Preferences' => '6.0.0', |
|
| 55 | - 'OC_Search_Provider' => '6.0.0', |
|
| 56 | - 'OC_Search_Result' => '6.0.0', |
|
| 57 | - 'OC_Request' => '6.0.0', |
|
| 58 | - 'OC_Response' => '6.0.0', |
|
| 59 | - 'OC_Template' => '6.0.0', |
|
| 60 | - 'OC_User' => '6.0.0', |
|
| 61 | - 'OC_Util' => '6.0.0', |
|
| 62 | - ]; |
|
| 63 | - } |
|
| 33 | + /** |
|
| 34 | + * @return array |
|
| 35 | + */ |
|
| 36 | + public function getLocalClasses() { |
|
| 37 | + return [ |
|
| 38 | + // classes replaced by the public api |
|
| 39 | + 'OC_API' => '6.0.0', |
|
| 40 | + 'OC_App' => '6.0.0', |
|
| 41 | + 'OC_AppConfig' => '6.0.0', |
|
| 42 | + 'OC_Avatar' => '6.0.0', |
|
| 43 | + 'OC_BackgroundJob' => '6.0.0', |
|
| 44 | + 'OC_Config' => '6.0.0', |
|
| 45 | + 'OC_DB' => '6.0.0', |
|
| 46 | + 'OC_Files' => '6.0.0', |
|
| 47 | + 'OC_Helper' => '6.0.0', |
|
| 48 | + 'OC_Hook' => '6.0.0', |
|
| 49 | + 'OC_Image' => '6.0.0', |
|
| 50 | + 'OC_JSON' => '6.0.0', |
|
| 51 | + 'OC_L10N' => '6.0.0', |
|
| 52 | + 'OC_Log' => '6.0.0', |
|
| 53 | + 'OC_Mail' => '6.0.0', |
|
| 54 | + 'OC_Preferences' => '6.0.0', |
|
| 55 | + 'OC_Search_Provider' => '6.0.0', |
|
| 56 | + 'OC_Search_Result' => '6.0.0', |
|
| 57 | + 'OC_Request' => '6.0.0', |
|
| 58 | + 'OC_Response' => '6.0.0', |
|
| 59 | + 'OC_Template' => '6.0.0', |
|
| 60 | + 'OC_User' => '6.0.0', |
|
| 61 | + 'OC_Util' => '6.0.0', |
|
| 62 | + ]; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - public function getLocalConstants() { |
|
| 69 | - return []; |
|
| 70 | - } |
|
| 65 | + /** |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + public function getLocalConstants() { |
|
| 69 | + return []; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function getLocalFunctions() { |
|
| 76 | - return []; |
|
| 77 | - } |
|
| 72 | + /** |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function getLocalFunctions() { |
|
| 76 | + return []; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - public function getLocalMethods() { |
|
| 83 | - return []; |
|
| 84 | - } |
|
| 79 | + /** |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + public function getLocalMethods() { |
|
| 83 | + return []; |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -23,57 +23,57 @@ |
||
| 23 | 23 | namespace OC\App\CodeChecker; |
| 24 | 24 | |
| 25 | 25 | class StrongComparisonCheck implements ICheck { |
| 26 | - /** @var ICheck */ |
|
| 27 | - protected $check; |
|
| 26 | + /** @var ICheck */ |
|
| 27 | + protected $check; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param ICheck $check |
|
| 31 | - */ |
|
| 32 | - public function __construct(ICheck $check) { |
|
| 33 | - $this->check = $check; |
|
| 34 | - } |
|
| 29 | + /** |
|
| 30 | + * @param ICheck $check |
|
| 31 | + */ |
|
| 32 | + public function __construct(ICheck $check) { |
|
| 33 | + $this->check = $check; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param int $errorCode |
|
| 38 | - * @param string $errorObject |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function getDescription($errorCode, $errorObject) { |
|
| 42 | - return $this->check->getDescription($errorCode, $errorObject); |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * @param int $errorCode |
|
| 38 | + * @param string $errorObject |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function getDescription($errorCode, $errorObject) { |
|
| 42 | + return $this->check->getDescription($errorCode, $errorObject); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function getClasses() { |
|
| 49 | - return $this->check->getClasses(); |
|
| 50 | - } |
|
| 45 | + /** |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function getClasses() { |
|
| 49 | + return $this->check->getClasses(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - public function getConstants() { |
|
| 56 | - return $this->check->getConstants(); |
|
| 57 | - } |
|
| 52 | + /** |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + public function getConstants() { |
|
| 56 | + return $this->check->getConstants(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function getFunctions() { |
|
| 63 | - return $this->check->getFunctions(); |
|
| 64 | - } |
|
| 59 | + /** |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function getFunctions() { |
|
| 63 | + return $this->check->getFunctions(); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function getMethods() { |
|
| 70 | - return $this->check->getMethods(); |
|
| 71 | - } |
|
| 66 | + /** |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function getMethods() { |
|
| 70 | + return $this->check->getMethods(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return bool |
|
| 75 | - */ |
|
| 76 | - public function checkStrongComparisons() { |
|
| 77 | - return true; |
|
| 78 | - } |
|
| 73 | + /** |
|
| 74 | + * @return bool |
|
| 75 | + */ |
|
| 76 | + public function checkStrongComparisons() { |
|
| 77 | + return true; |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -38,95 +38,95 @@ |
||
| 38 | 38 | |
| 39 | 39 | class CodeChecker extends BasicEmitter { |
| 40 | 40 | |
| 41 | - const CLASS_EXTENDS_NOT_ALLOWED = 1000; |
|
| 42 | - const CLASS_IMPLEMENTS_NOT_ALLOWED = 1001; |
|
| 43 | - const STATIC_CALL_NOT_ALLOWED = 1002; |
|
| 44 | - const CLASS_CONST_FETCH_NOT_ALLOWED = 1003; |
|
| 45 | - const CLASS_NEW_NOT_ALLOWED = 1004; |
|
| 46 | - const OP_OPERATOR_USAGE_DISCOURAGED = 1005; |
|
| 47 | - const CLASS_USE_NOT_ALLOWED = 1006; |
|
| 48 | - const CLASS_METHOD_CALL_NOT_ALLOWED = 1007; |
|
| 49 | - |
|
| 50 | - /** @var Parser */ |
|
| 51 | - private $parser; |
|
| 52 | - |
|
| 53 | - /** @var ICheck */ |
|
| 54 | - protected $checkList; |
|
| 55 | - |
|
| 56 | - public function __construct(ICheck $checkList) { |
|
| 57 | - $this->checkList = $checkList; |
|
| 58 | - $this->parser = new Parser(new Lexer); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $appId |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public function analyse($appId) { |
|
| 66 | - $appPath = \OC_App::getAppPath($appId); |
|
| 67 | - if ($appPath === false) { |
|
| 68 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return $this->analyseFolder($appId, $appPath); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $appId |
|
| 76 | - * @param string $folder |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function analyseFolder($appId, $folder) { |
|
| 80 | - $errors = []; |
|
| 81 | - |
|
| 82 | - $excludedDirectories = ['vendor', '3rdparty', '.git', 'l10n', 'tests', 'test']; |
|
| 83 | - if ($appId === 'password_policy') { |
|
| 84 | - $excludedDirectories[] = 'lists'; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $excludes = array_map(function($item) use ($folder) { |
|
| 88 | - return $folder . '/' . $item; |
|
| 89 | - }, $excludedDirectories); |
|
| 90 | - |
|
| 91 | - $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); |
|
| 92 | - $iterator = new RecursiveCallbackFilterIterator($iterator, function($item) use ($folder, $excludes){ |
|
| 93 | - /** @var SplFileInfo $item */ |
|
| 94 | - foreach($excludes as $exclude) { |
|
| 95 | - if (substr($item->getPath(), 0, strlen($exclude)) === $exclude) { |
|
| 96 | - return false; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - return true; |
|
| 100 | - }); |
|
| 101 | - $iterator = new RecursiveIteratorIterator($iterator); |
|
| 102 | - $iterator = new RegexIterator($iterator, '/^.+\.php$/i'); |
|
| 103 | - |
|
| 104 | - foreach ($iterator as $file) { |
|
| 105 | - /** @var SplFileInfo $file */ |
|
| 106 | - $this->emit('CodeChecker', 'analyseFileBegin', [$file->getPathname()]); |
|
| 107 | - $fileErrors = $this->analyseFile($file); |
|
| 108 | - $this->emit('CodeChecker', 'analyseFileFinished', [$file->getPathname(), $fileErrors]); |
|
| 109 | - $errors = array_merge($fileErrors, $errors); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return $errors; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $file |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - public function analyseFile($file) { |
|
| 121 | - $code = file_get_contents($file); |
|
| 122 | - $statements = $this->parser->parse($code); |
|
| 123 | - |
|
| 124 | - $visitor = new NodeVisitor($this->checkList); |
|
| 125 | - $traverser = new NodeTraverser; |
|
| 126 | - $traverser->addVisitor($visitor); |
|
| 127 | - |
|
| 128 | - $traverser->traverse($statements); |
|
| 129 | - |
|
| 130 | - return $visitor->errors; |
|
| 131 | - } |
|
| 41 | + const CLASS_EXTENDS_NOT_ALLOWED = 1000; |
|
| 42 | + const CLASS_IMPLEMENTS_NOT_ALLOWED = 1001; |
|
| 43 | + const STATIC_CALL_NOT_ALLOWED = 1002; |
|
| 44 | + const CLASS_CONST_FETCH_NOT_ALLOWED = 1003; |
|
| 45 | + const CLASS_NEW_NOT_ALLOWED = 1004; |
|
| 46 | + const OP_OPERATOR_USAGE_DISCOURAGED = 1005; |
|
| 47 | + const CLASS_USE_NOT_ALLOWED = 1006; |
|
| 48 | + const CLASS_METHOD_CALL_NOT_ALLOWED = 1007; |
|
| 49 | + |
|
| 50 | + /** @var Parser */ |
|
| 51 | + private $parser; |
|
| 52 | + |
|
| 53 | + /** @var ICheck */ |
|
| 54 | + protected $checkList; |
|
| 55 | + |
|
| 56 | + public function __construct(ICheck $checkList) { |
|
| 57 | + $this->checkList = $checkList; |
|
| 58 | + $this->parser = new Parser(new Lexer); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $appId |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public function analyse($appId) { |
|
| 66 | + $appPath = \OC_App::getAppPath($appId); |
|
| 67 | + if ($appPath === false) { |
|
| 68 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return $this->analyseFolder($appId, $appPath); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $appId |
|
| 76 | + * @param string $folder |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function analyseFolder($appId, $folder) { |
|
| 80 | + $errors = []; |
|
| 81 | + |
|
| 82 | + $excludedDirectories = ['vendor', '3rdparty', '.git', 'l10n', 'tests', 'test']; |
|
| 83 | + if ($appId === 'password_policy') { |
|
| 84 | + $excludedDirectories[] = 'lists'; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $excludes = array_map(function($item) use ($folder) { |
|
| 88 | + return $folder . '/' . $item; |
|
| 89 | + }, $excludedDirectories); |
|
| 90 | + |
|
| 91 | + $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); |
|
| 92 | + $iterator = new RecursiveCallbackFilterIterator($iterator, function($item) use ($folder, $excludes){ |
|
| 93 | + /** @var SplFileInfo $item */ |
|
| 94 | + foreach($excludes as $exclude) { |
|
| 95 | + if (substr($item->getPath(), 0, strlen($exclude)) === $exclude) { |
|
| 96 | + return false; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + return true; |
|
| 100 | + }); |
|
| 101 | + $iterator = new RecursiveIteratorIterator($iterator); |
|
| 102 | + $iterator = new RegexIterator($iterator, '/^.+\.php$/i'); |
|
| 103 | + |
|
| 104 | + foreach ($iterator as $file) { |
|
| 105 | + /** @var SplFileInfo $file */ |
|
| 106 | + $this->emit('CodeChecker', 'analyseFileBegin', [$file->getPathname()]); |
|
| 107 | + $fileErrors = $this->analyseFile($file); |
|
| 108 | + $this->emit('CodeChecker', 'analyseFileFinished', [$file->getPathname(), $fileErrors]); |
|
| 109 | + $errors = array_merge($fileErrors, $errors); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $errors; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $file |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + public function analyseFile($file) { |
|
| 121 | + $code = file_get_contents($file); |
|
| 122 | + $statements = $this->parser->parse($code); |
|
| 123 | + |
|
| 124 | + $visitor = new NodeVisitor($this->checkList); |
|
| 125 | + $traverser = new NodeTraverser; |
|
| 126 | + $traverser->addVisitor($visitor); |
|
| 127 | + |
|
| 128 | + $traverser->traverse($statements); |
|
| 129 | + |
|
| 130 | + return $visitor->errors; |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | const CLASS_IMPLEMENTS_NOT_ALLOWED = 1001; |
| 43 | 43 | const STATIC_CALL_NOT_ALLOWED = 1002; |
| 44 | 44 | const CLASS_CONST_FETCH_NOT_ALLOWED = 1003; |
| 45 | - const CLASS_NEW_NOT_ALLOWED = 1004; |
|
| 46 | - const OP_OPERATOR_USAGE_DISCOURAGED = 1005; |
|
| 47 | - const CLASS_USE_NOT_ALLOWED = 1006; |
|
| 48 | - const CLASS_METHOD_CALL_NOT_ALLOWED = 1007; |
|
| 45 | + const CLASS_NEW_NOT_ALLOWED = 1004; |
|
| 46 | + const OP_OPERATOR_USAGE_DISCOURAGED = 1005; |
|
| 47 | + const CLASS_USE_NOT_ALLOWED = 1006; |
|
| 48 | + const CLASS_METHOD_CALL_NOT_ALLOWED = 1007; |
|
| 49 | 49 | |
| 50 | 50 | /** @var Parser */ |
| 51 | 51 | private $parser; |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $excludes = array_map(function($item) use ($folder) { |
| 88 | - return $folder . '/' . $item; |
|
| 88 | + return $folder.'/'.$item; |
|
| 89 | 89 | }, $excludedDirectories); |
| 90 | 90 | |
| 91 | 91 | $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); |
| 92 | 92 | $iterator = new RecursiveCallbackFilterIterator($iterator, function($item) use ($folder, $excludes){ |
| 93 | 93 | /** @var SplFileInfo $item */ |
| 94 | - foreach($excludes as $exclude) { |
|
| 94 | + foreach ($excludes as $exclude) { |
|
| 95 | 95 | if (substr($item->getPath(), 0, strlen($exclude)) === $exclude) { |
| 96 | 96 | return false; |
| 97 | 97 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | $errors = []; |
| 80 | 80 | |
| 81 | - $info = $this->infoParser->parse($appPath . '/appinfo/info.xml'); |
|
| 81 | + $info = $this->infoParser->parse($appPath.'/appinfo/info.xml'); |
|
| 82 | 82 | |
| 83 | 83 | if (isset($info['dependencies']['owncloud']['@attributes']['min-version']) && (isset($info['requiremin']) || isset($info['require']))) { |
| 84 | 84 | $this->emit('InfoChecker', 'duplicateRequirement', ['min']); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | foreach ($info as $key => $value) { |
| 110 | - if(is_array($value)) { |
|
| 110 | + if (is_array($value)) { |
|
| 111 | 111 | $value = json_encode($value); |
| 112 | 112 | } |
| 113 | 113 | if (in_array($key, $this->mandatoryFields)) { |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | if (in_array($key, $this->deprecatedFields)) { |
| 124 | 124 | // skip empty arrays - empty arrays for remote and public are always added |
| 125 | - if($value === '[]' && in_array($key, ['public', 'remote', 'info'])) { |
|
| 125 | + if ($value === '[]' && in_array($key, ['public', 'remote', 'info'])) { |
|
| 126 | 126 | continue; |
| 127 | 127 | } |
| 128 | 128 | $this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | foreach ($this->mandatoryFields as $key) { |
| 136 | - if(!isset($info[$key])) { |
|
| 136 | + if (!isset($info[$key])) { |
|
| 137 | 137 | $this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]); |
| 138 | 138 | $errors[] = [ |
| 139 | 139 | 'type' => 'mandatoryFieldMissing', |
@@ -142,17 +142,17 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $versionFile = $appPath . '/appinfo/version'; |
|
| 145 | + $versionFile = $appPath.'/appinfo/version'; |
|
| 146 | 146 | if (is_file($versionFile)) { |
| 147 | 147 | $version = trim(file_get_contents($versionFile)); |
| 148 | 148 | if (isset($info['version'])) { |
| 149 | - if($info['version'] !== $version) { |
|
| 149 | + if ($info['version'] !== $version) { |
|
| 150 | 150 | $this->emit('InfoChecker', 'differentVersions', |
| 151 | 151 | [$version, $info['version']]); |
| 152 | 152 | $errors[] = [ |
| 153 | 153 | 'type' => 'differentVersions', |
| 154 | - 'message' => 'appinfo/version: ' . $version . |
|
| 155 | - ' - appinfo/info.xml: ' . $info['version'], |
|
| 154 | + 'message' => 'appinfo/version: '.$version. |
|
| 155 | + ' - appinfo/info.xml: '.$info['version'], |
|
| 156 | 156 | ]; |
| 157 | 157 | } else { |
| 158 | 158 | $this->emit('InfoChecker', 'sameVersions', [$versionFile]); |
@@ -28,134 +28,134 @@ |
||
| 28 | 28 | |
| 29 | 29 | class InfoChecker extends BasicEmitter { |
| 30 | 30 | |
| 31 | - /** @var InfoParser */ |
|
| 32 | - private $infoParser; |
|
| 33 | - |
|
| 34 | - private $mandatoryFields = [ |
|
| 35 | - 'author', |
|
| 36 | - 'description', |
|
| 37 | - 'id', |
|
| 38 | - 'licence', |
|
| 39 | - 'name', |
|
| 40 | - ]; |
|
| 41 | - private $optionalFields = [ |
|
| 42 | - 'bugs', |
|
| 43 | - 'category', |
|
| 44 | - 'default_enable', |
|
| 45 | - 'dependencies', // TODO: Mandatory as of ownCloud 11 |
|
| 46 | - 'documentation', |
|
| 47 | - 'namespace', |
|
| 48 | - 'ocsid', |
|
| 49 | - 'public', |
|
| 50 | - 'remote', |
|
| 51 | - 'repository', |
|
| 52 | - 'types', |
|
| 53 | - 'version', |
|
| 54 | - 'website', |
|
| 55 | - ]; |
|
| 56 | - private $deprecatedFields = [ |
|
| 57 | - 'info', |
|
| 58 | - 'require', |
|
| 59 | - 'requiremax', |
|
| 60 | - 'requiremin', |
|
| 61 | - 'shipped', |
|
| 62 | - 'standalone', |
|
| 63 | - ]; |
|
| 64 | - |
|
| 65 | - public function __construct(InfoParser $infoParser) { |
|
| 66 | - $this->infoParser = $infoParser; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param string $appId |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - public function analyse($appId) { |
|
| 74 | - $appPath = \OC_App::getAppPath($appId); |
|
| 75 | - if ($appPath === false) { |
|
| 76 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $errors = []; |
|
| 80 | - |
|
| 81 | - $info = $this->infoParser->parse($appPath . '/appinfo/info.xml'); |
|
| 82 | - |
|
| 83 | - if (isset($info['dependencies']['owncloud']['@attributes']['min-version']) && (isset($info['requiremin']) || isset($info['require']))) { |
|
| 84 | - $this->emit('InfoChecker', 'duplicateRequirement', ['min']); |
|
| 85 | - $errors[] = [ |
|
| 86 | - 'type' => 'duplicateRequirement', |
|
| 87 | - 'field' => 'min', |
|
| 88 | - ]; |
|
| 89 | - } else if (!isset($info['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 90 | - $this->emit('InfoChecker', 'missingRequirement', ['min']); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (isset($info['dependencies']['owncloud']['@attributes']['max-version']) && isset($info['requiremax'])) { |
|
| 94 | - $this->emit('InfoChecker', 'duplicateRequirement', ['max']); |
|
| 95 | - $errors[] = [ |
|
| 96 | - 'type' => 'duplicateRequirement', |
|
| 97 | - 'field' => 'max', |
|
| 98 | - ]; |
|
| 99 | - } else if (!isset($info['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 100 | - $this->emit('InfoChecker', 'missingRequirement', ['max']); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - foreach ($info as $key => $value) { |
|
| 104 | - if(is_array($value)) { |
|
| 105 | - $value = json_encode($value); |
|
| 106 | - } |
|
| 107 | - if (in_array($key, $this->mandatoryFields)) { |
|
| 108 | - $this->emit('InfoChecker', 'mandatoryFieldFound', [$key, $value]); |
|
| 109 | - continue; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if (in_array($key, $this->optionalFields)) { |
|
| 113 | - $this->emit('InfoChecker', 'optionalFieldFound', [$key, $value]); |
|
| 114 | - continue; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if (in_array($key, $this->deprecatedFields)) { |
|
| 118 | - // skip empty arrays - empty arrays for remote and public are always added |
|
| 119 | - if($value === '[]' && in_array($key, ['public', 'remote', 'info'])) { |
|
| 120 | - continue; |
|
| 121 | - } |
|
| 122 | - $this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]); |
|
| 123 | - continue; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $this->emit('InfoChecker', 'unusedFieldFound', [$key, $value]); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - foreach ($this->mandatoryFields as $key) { |
|
| 130 | - if(!isset($info[$key])) { |
|
| 131 | - $this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]); |
|
| 132 | - $errors[] = [ |
|
| 133 | - 'type' => 'mandatoryFieldMissing', |
|
| 134 | - 'field' => $key, |
|
| 135 | - ]; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $versionFile = $appPath . '/appinfo/version'; |
|
| 140 | - if (is_file($versionFile)) { |
|
| 141 | - $version = trim(file_get_contents($versionFile)); |
|
| 142 | - if (isset($info['version'])) { |
|
| 143 | - if($info['version'] !== $version) { |
|
| 144 | - $this->emit('InfoChecker', 'differentVersions', |
|
| 145 | - [$version, $info['version']]); |
|
| 146 | - $errors[] = [ |
|
| 147 | - 'type' => 'differentVersions', |
|
| 148 | - 'message' => 'appinfo/version: ' . $version . |
|
| 149 | - ' - appinfo/info.xml: ' . $info['version'], |
|
| 150 | - ]; |
|
| 151 | - } else { |
|
| 152 | - $this->emit('InfoChecker', 'sameVersions', [$versionFile]); |
|
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - $this->emit('InfoChecker', 'migrateVersion', [$version]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return $errors; |
|
| 160 | - } |
|
| 31 | + /** @var InfoParser */ |
|
| 32 | + private $infoParser; |
|
| 33 | + |
|
| 34 | + private $mandatoryFields = [ |
|
| 35 | + 'author', |
|
| 36 | + 'description', |
|
| 37 | + 'id', |
|
| 38 | + 'licence', |
|
| 39 | + 'name', |
|
| 40 | + ]; |
|
| 41 | + private $optionalFields = [ |
|
| 42 | + 'bugs', |
|
| 43 | + 'category', |
|
| 44 | + 'default_enable', |
|
| 45 | + 'dependencies', // TODO: Mandatory as of ownCloud 11 |
|
| 46 | + 'documentation', |
|
| 47 | + 'namespace', |
|
| 48 | + 'ocsid', |
|
| 49 | + 'public', |
|
| 50 | + 'remote', |
|
| 51 | + 'repository', |
|
| 52 | + 'types', |
|
| 53 | + 'version', |
|
| 54 | + 'website', |
|
| 55 | + ]; |
|
| 56 | + private $deprecatedFields = [ |
|
| 57 | + 'info', |
|
| 58 | + 'require', |
|
| 59 | + 'requiremax', |
|
| 60 | + 'requiremin', |
|
| 61 | + 'shipped', |
|
| 62 | + 'standalone', |
|
| 63 | + ]; |
|
| 64 | + |
|
| 65 | + public function __construct(InfoParser $infoParser) { |
|
| 66 | + $this->infoParser = $infoParser; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param string $appId |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + public function analyse($appId) { |
|
| 74 | + $appPath = \OC_App::getAppPath($appId); |
|
| 75 | + if ($appPath === false) { |
|
| 76 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $errors = []; |
|
| 80 | + |
|
| 81 | + $info = $this->infoParser->parse($appPath . '/appinfo/info.xml'); |
|
| 82 | + |
|
| 83 | + if (isset($info['dependencies']['owncloud']['@attributes']['min-version']) && (isset($info['requiremin']) || isset($info['require']))) { |
|
| 84 | + $this->emit('InfoChecker', 'duplicateRequirement', ['min']); |
|
| 85 | + $errors[] = [ |
|
| 86 | + 'type' => 'duplicateRequirement', |
|
| 87 | + 'field' => 'min', |
|
| 88 | + ]; |
|
| 89 | + } else if (!isset($info['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 90 | + $this->emit('InfoChecker', 'missingRequirement', ['min']); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (isset($info['dependencies']['owncloud']['@attributes']['max-version']) && isset($info['requiremax'])) { |
|
| 94 | + $this->emit('InfoChecker', 'duplicateRequirement', ['max']); |
|
| 95 | + $errors[] = [ |
|
| 96 | + 'type' => 'duplicateRequirement', |
|
| 97 | + 'field' => 'max', |
|
| 98 | + ]; |
|
| 99 | + } else if (!isset($info['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 100 | + $this->emit('InfoChecker', 'missingRequirement', ['max']); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + foreach ($info as $key => $value) { |
|
| 104 | + if(is_array($value)) { |
|
| 105 | + $value = json_encode($value); |
|
| 106 | + } |
|
| 107 | + if (in_array($key, $this->mandatoryFields)) { |
|
| 108 | + $this->emit('InfoChecker', 'mandatoryFieldFound', [$key, $value]); |
|
| 109 | + continue; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if (in_array($key, $this->optionalFields)) { |
|
| 113 | + $this->emit('InfoChecker', 'optionalFieldFound', [$key, $value]); |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if (in_array($key, $this->deprecatedFields)) { |
|
| 118 | + // skip empty arrays - empty arrays for remote and public are always added |
|
| 119 | + if($value === '[]' && in_array($key, ['public', 'remote', 'info'])) { |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 122 | + $this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]); |
|
| 123 | + continue; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $this->emit('InfoChecker', 'unusedFieldFound', [$key, $value]); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + foreach ($this->mandatoryFields as $key) { |
|
| 130 | + if(!isset($info[$key])) { |
|
| 131 | + $this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]); |
|
| 132 | + $errors[] = [ |
|
| 133 | + 'type' => 'mandatoryFieldMissing', |
|
| 134 | + 'field' => $key, |
|
| 135 | + ]; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $versionFile = $appPath . '/appinfo/version'; |
|
| 140 | + if (is_file($versionFile)) { |
|
| 141 | + $version = trim(file_get_contents($versionFile)); |
|
| 142 | + if (isset($info['version'])) { |
|
| 143 | + if($info['version'] !== $version) { |
|
| 144 | + $this->emit('InfoChecker', 'differentVersions', |
|
| 145 | + [$version, $info['version']]); |
|
| 146 | + $errors[] = [ |
|
| 147 | + 'type' => 'differentVersions', |
|
| 148 | + 'message' => 'appinfo/version: ' . $version . |
|
| 149 | + ' - appinfo/info.xml: ' . $info['version'], |
|
| 150 | + ]; |
|
| 151 | + } else { |
|
| 152 | + $this->emit('InfoChecker', 'sameVersions', [$versionFile]); |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + $this->emit('InfoChecker', 'migrateVersion', [$version]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return $errors; |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -22,35 +22,35 @@ |
||
| 22 | 22 | namespace OC\App\CodeChecker; |
| 23 | 23 | |
| 24 | 24 | interface ICheck { |
| 25 | - /** |
|
| 26 | - * @param int $errorCode |
|
| 27 | - * @param string $errorObject |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getDescription($errorCode, $errorObject); |
|
| 25 | + /** |
|
| 26 | + * @param int $errorCode |
|
| 27 | + * @param string $errorObject |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getDescription($errorCode, $errorObject); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return array E.g.: `'ClassName' => 'oc version',` |
|
| 34 | - */ |
|
| 35 | - public function getClasses(); |
|
| 32 | + /** |
|
| 33 | + * @return array E.g.: `'ClassName' => 'oc version',` |
|
| 34 | + */ |
|
| 35 | + public function getClasses(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
| 39 | - */ |
|
| 40 | - public function getConstants(); |
|
| 37 | + /** |
|
| 38 | + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
| 39 | + */ |
|
| 40 | + public function getConstants(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return array E.g.: `'functionName' => 'oc version',` |
|
| 44 | - */ |
|
| 45 | - public function getFunctions(); |
|
| 42 | + /** |
|
| 43 | + * @return array E.g.: `'functionName' => 'oc version',` |
|
| 44 | + */ |
|
| 45 | + public function getFunctions(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
| 49 | - */ |
|
| 50 | - public function getMethods(); |
|
| 47 | + /** |
|
| 48 | + * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
| 49 | + */ |
|
| 50 | + public function getMethods(); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return bool |
|
| 54 | - */ |
|
| 55 | - public function checkStrongComparisons(); |
|
| 52 | + /** |
|
| 53 | + * @return bool |
|
| 54 | + */ |
|
| 55 | + public function checkStrongComparisons(); |
|
| 56 | 56 | } |