@@ -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 | } |
@@ -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 | } |
@@ -36,104 +36,104 @@ |
||
| 36 | 36 | |
| 37 | 37 | class CodeChecker extends BasicEmitter { |
| 38 | 38 | |
| 39 | - const CLASS_EXTENDS_NOT_ALLOWED = 1000; |
|
| 40 | - const CLASS_IMPLEMENTS_NOT_ALLOWED = 1001; |
|
| 41 | - const STATIC_CALL_NOT_ALLOWED = 1002; |
|
| 42 | - const CLASS_CONST_FETCH_NOT_ALLOWED = 1003; |
|
| 43 | - const CLASS_NEW_NOT_ALLOWED = 1004; |
|
| 44 | - const OP_OPERATOR_USAGE_DISCOURAGED = 1005; |
|
| 45 | - const CLASS_USE_NOT_ALLOWED = 1006; |
|
| 46 | - const CLASS_METHOD_CALL_NOT_ALLOWED = 1007; |
|
| 47 | - |
|
| 48 | - /** @var Parser */ |
|
| 49 | - private $parser; |
|
| 50 | - |
|
| 51 | - /** @var ICheck */ |
|
| 52 | - protected $checkList; |
|
| 53 | - |
|
| 54 | - /** @var bool */ |
|
| 55 | - protected $checkMigrationSchema; |
|
| 56 | - |
|
| 57 | - public function __construct(ICheck $checkList, $checkMigrationSchema) { |
|
| 58 | - $this->checkList = $checkList; |
|
| 59 | - $this->checkMigrationSchema = $checkMigrationSchema; |
|
| 60 | - $this->parser = new Parser(new Lexer); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param string $appId |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function analyse($appId) { |
|
| 68 | - $appPath = \OC_App::getAppPath($appId); |
|
| 69 | - if ($appPath === false) { |
|
| 70 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $this->analyseFolder($appId, $appPath); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $appId |
|
| 78 | - * @param string $folder |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function analyseFolder($appId, $folder) { |
|
| 82 | - $errors = []; |
|
| 83 | - |
|
| 84 | - $excludedDirectories = ['vendor', '3rdparty', '.git', 'l10n', 'tests', 'test']; |
|
| 85 | - if ($appId === 'password_policy') { |
|
| 86 | - $excludedDirectories[] = 'lists'; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $excludes = array_map(function($item) use ($folder) { |
|
| 90 | - return $folder . '/' . $item; |
|
| 91 | - }, $excludedDirectories); |
|
| 92 | - |
|
| 93 | - $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); |
|
| 94 | - $iterator = new RecursiveCallbackFilterIterator($iterator, function($item) use ($folder, $excludes){ |
|
| 95 | - /** @var SplFileInfo $item */ |
|
| 96 | - foreach($excludes as $exclude) { |
|
| 97 | - if (substr($item->getPath(), 0, strlen($exclude)) === $exclude) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - return true; |
|
| 102 | - }); |
|
| 103 | - $iterator = new RecursiveIteratorIterator($iterator); |
|
| 104 | - $iterator = new RegexIterator($iterator, '/^.+\.php$/i'); |
|
| 105 | - |
|
| 106 | - foreach ($iterator as $file) { |
|
| 107 | - /** @var SplFileInfo $file */ |
|
| 108 | - $this->emit('CodeChecker', 'analyseFileBegin', [$file->getPathname()]); |
|
| 109 | - $fileErrors = $this->analyseFile($file); |
|
| 110 | - $this->emit('CodeChecker', 'analyseFileFinished', [$file->getPathname(), $fileErrors]); |
|
| 111 | - $errors = array_merge($fileErrors, $errors); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $errors; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param string $file |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function analyseFile($file) { |
|
| 123 | - $code = file_get_contents($file); |
|
| 124 | - $statements = $this->parser->parse($code); |
|
| 125 | - |
|
| 126 | - $visitor = new NodeVisitor($this->checkList); |
|
| 127 | - $migrationVisitor = new MigrationSchemaChecker(); |
|
| 128 | - $traverser = new NodeTraverser; |
|
| 129 | - $traverser->addVisitor($visitor); |
|
| 130 | - |
|
| 131 | - if ($this->checkMigrationSchema && preg_match('#^.+\\/Migration\\/Version[^\\/]{1,255}\\.php$#i', $file)) { |
|
| 132 | - $traverser->addVisitor($migrationVisitor); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $traverser->traverse($statements); |
|
| 136 | - |
|
| 137 | - return array_merge($visitor->errors, $migrationVisitor->errors); |
|
| 138 | - } |
|
| 39 | + const CLASS_EXTENDS_NOT_ALLOWED = 1000; |
|
| 40 | + const CLASS_IMPLEMENTS_NOT_ALLOWED = 1001; |
|
| 41 | + const STATIC_CALL_NOT_ALLOWED = 1002; |
|
| 42 | + const CLASS_CONST_FETCH_NOT_ALLOWED = 1003; |
|
| 43 | + const CLASS_NEW_NOT_ALLOWED = 1004; |
|
| 44 | + const OP_OPERATOR_USAGE_DISCOURAGED = 1005; |
|
| 45 | + const CLASS_USE_NOT_ALLOWED = 1006; |
|
| 46 | + const CLASS_METHOD_CALL_NOT_ALLOWED = 1007; |
|
| 47 | + |
|
| 48 | + /** @var Parser */ |
|
| 49 | + private $parser; |
|
| 50 | + |
|
| 51 | + /** @var ICheck */ |
|
| 52 | + protected $checkList; |
|
| 53 | + |
|
| 54 | + /** @var bool */ |
|
| 55 | + protected $checkMigrationSchema; |
|
| 56 | + |
|
| 57 | + public function __construct(ICheck $checkList, $checkMigrationSchema) { |
|
| 58 | + $this->checkList = $checkList; |
|
| 59 | + $this->checkMigrationSchema = $checkMigrationSchema; |
|
| 60 | + $this->parser = new Parser(new Lexer); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param string $appId |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function analyse($appId) { |
|
| 68 | + $appPath = \OC_App::getAppPath($appId); |
|
| 69 | + if ($appPath === false) { |
|
| 70 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $this->analyseFolder($appId, $appPath); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $appId |
|
| 78 | + * @param string $folder |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function analyseFolder($appId, $folder) { |
|
| 82 | + $errors = []; |
|
| 83 | + |
|
| 84 | + $excludedDirectories = ['vendor', '3rdparty', '.git', 'l10n', 'tests', 'test']; |
|
| 85 | + if ($appId === 'password_policy') { |
|
| 86 | + $excludedDirectories[] = 'lists'; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $excludes = array_map(function($item) use ($folder) { |
|
| 90 | + return $folder . '/' . $item; |
|
| 91 | + }, $excludedDirectories); |
|
| 92 | + |
|
| 93 | + $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); |
|
| 94 | + $iterator = new RecursiveCallbackFilterIterator($iterator, function($item) use ($folder, $excludes){ |
|
| 95 | + /** @var SplFileInfo $item */ |
|
| 96 | + foreach($excludes as $exclude) { |
|
| 97 | + if (substr($item->getPath(), 0, strlen($exclude)) === $exclude) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + return true; |
|
| 102 | + }); |
|
| 103 | + $iterator = new RecursiveIteratorIterator($iterator); |
|
| 104 | + $iterator = new RegexIterator($iterator, '/^.+\.php$/i'); |
|
| 105 | + |
|
| 106 | + foreach ($iterator as $file) { |
|
| 107 | + /** @var SplFileInfo $file */ |
|
| 108 | + $this->emit('CodeChecker', 'analyseFileBegin', [$file->getPathname()]); |
|
| 109 | + $fileErrors = $this->analyseFile($file); |
|
| 110 | + $this->emit('CodeChecker', 'analyseFileFinished', [$file->getPathname(), $fileErrors]); |
|
| 111 | + $errors = array_merge($fileErrors, $errors); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $errors; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param string $file |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function analyseFile($file) { |
|
| 123 | + $code = file_get_contents($file); |
|
| 124 | + $statements = $this->parser->parse($code); |
|
| 125 | + |
|
| 126 | + $visitor = new NodeVisitor($this->checkList); |
|
| 127 | + $migrationVisitor = new MigrationSchemaChecker(); |
|
| 128 | + $traverser = new NodeTraverser; |
|
| 129 | + $traverser->addVisitor($visitor); |
|
| 130 | + |
|
| 131 | + if ($this->checkMigrationSchema && preg_match('#^.+\\/Migration\\/Version[^\\/]{1,255}\\.php$#i', $file)) { |
|
| 132 | + $traverser->addVisitor($migrationVisitor); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $traverser->traverse($statements); |
|
| 136 | + |
|
| 137 | + return array_merge($visitor->errors, $migrationVisitor->errors); |
|
| 138 | + } |
|
| 139 | 139 | } |
@@ -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 | } |
@@ -30,200 +30,200 @@ |
||
| 30 | 30 | * @package OC\App |
| 31 | 31 | */ |
| 32 | 32 | class PlatformRepository { |
| 33 | - public function __construct() { |
|
| 34 | - $this->packages = $this->initialize(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - protected function initialize() { |
|
| 38 | - $loadedExtensions = get_loaded_extensions(); |
|
| 39 | - $packages = array(); |
|
| 40 | - |
|
| 41 | - // Extensions scanning |
|
| 42 | - foreach ($loadedExtensions as $name) { |
|
| 43 | - if (in_array($name, array('standard', 'Core'))) { |
|
| 44 | - continue; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $ext = new \ReflectionExtension($name); |
|
| 48 | - try { |
|
| 49 | - $prettyVersion = $ext->getVersion(); |
|
| 50 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 51 | - } catch (\UnexpectedValueException $e) { |
|
| 52 | - $prettyVersion = '0'; |
|
| 53 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - foreach ($loadedExtensions as $name) { |
|
| 60 | - $prettyVersion = null; |
|
| 61 | - switch ($name) { |
|
| 62 | - case 'curl': |
|
| 63 | - $curlVersion = curl_version(); |
|
| 64 | - $prettyVersion = $curlVersion['version']; |
|
| 65 | - break; |
|
| 66 | - |
|
| 67 | - case 'iconv': |
|
| 68 | - $prettyVersion = ICONV_VERSION; |
|
| 69 | - break; |
|
| 70 | - |
|
| 71 | - case 'intl': |
|
| 72 | - $name = 'ICU'; |
|
| 73 | - if (defined('INTL_ICU_VERSION')) { |
|
| 74 | - $prettyVersion = INTL_ICU_VERSION; |
|
| 75 | - } else { |
|
| 76 | - $reflector = new \ReflectionExtension('intl'); |
|
| 77 | - |
|
| 78 | - ob_start(); |
|
| 79 | - $reflector->info(); |
|
| 80 | - $output = ob_get_clean(); |
|
| 81 | - |
|
| 82 | - preg_match('/^ICU version => (.*)$/m', $output, $matches); |
|
| 83 | - $prettyVersion = $matches[1]; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - break; |
|
| 87 | - |
|
| 88 | - case 'libxml': |
|
| 89 | - $prettyVersion = LIBXML_DOTTED_VERSION; |
|
| 90 | - break; |
|
| 91 | - |
|
| 92 | - case 'openssl': |
|
| 93 | - $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
| 94 | - return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
| 95 | - }, OPENSSL_VERSION_TEXT); |
|
| 96 | - break; |
|
| 97 | - |
|
| 98 | - case 'pcre': |
|
| 99 | - $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION); |
|
| 100 | - break; |
|
| 101 | - |
|
| 102 | - case 'uuid': |
|
| 103 | - $prettyVersion = phpversion('uuid'); |
|
| 104 | - break; |
|
| 105 | - |
|
| 106 | - case 'xsl': |
|
| 107 | - $prettyVersion = LIBXSLT_DOTTED_VERSION; |
|
| 108 | - break; |
|
| 109 | - |
|
| 110 | - default: |
|
| 111 | - // None handled extensions have no special cases, skip |
|
| 112 | - continue 2; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - try { |
|
| 116 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 117 | - } catch (\UnexpectedValueException $e) { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $packages; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - private function buildPackageName($name) { |
|
| 128 | - return str_replace(' ', '-', $name); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @param $name |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public function findLibrary($name) { |
|
| 136 | - $extName = $this->buildPackageName($name); |
|
| 137 | - if (isset($this->packages[$extName])) { |
|
| 138 | - return $this->packages[$extName]; |
|
| 139 | - } |
|
| 140 | - return null; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Normalizes a version string to be able to perform comparisons on it |
|
| 147 | - * |
|
| 148 | - * https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94 |
|
| 149 | - * |
|
| 150 | - * @param string $version |
|
| 151 | - * @param string $fullVersion optional complete version string to give more context |
|
| 152 | - * @throws \UnexpectedValueException |
|
| 153 | - * @return string |
|
| 154 | - */ |
|
| 155 | - public function normalizeVersion($version, $fullVersion = null) { |
|
| 156 | - $version = trim($version); |
|
| 157 | - if (null === $fullVersion) { |
|
| 158 | - $fullVersion = $version; |
|
| 159 | - } |
|
| 160 | - // ignore aliases and just assume the alias is required instead of the source |
|
| 161 | - if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) { |
|
| 162 | - $version = $match[1]; |
|
| 163 | - } |
|
| 164 | - // match master-like branches |
|
| 165 | - if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) { |
|
| 166 | - return '9999999-dev'; |
|
| 167 | - } |
|
| 168 | - if ('dev-' === strtolower(substr($version, 0, 4))) { |
|
| 169 | - return 'dev-' . substr($version, 4); |
|
| 170 | - } |
|
| 171 | - // match classical versioning |
|
| 172 | - if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 173 | - $version = $matches[1] |
|
| 174 | - . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 175 | - . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 176 | - . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 177 | - $index = 5; |
|
| 178 | - } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
| 179 | - $version = preg_replace('{\D}', '-', $matches[1]); |
|
| 180 | - $index = 2; |
|
| 181 | - } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 182 | - $version = $matches[1] |
|
| 183 | - . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 184 | - . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 185 | - . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 186 | - $index = 5; |
|
| 187 | - } |
|
| 188 | - // add version modifiers if a version was matched |
|
| 189 | - if (isset($index)) { |
|
| 190 | - if (!empty($matches[$index])) { |
|
| 191 | - if ('stable' === $matches[$index]) { |
|
| 192 | - return $version; |
|
| 193 | - } |
|
| 194 | - $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 195 | - } |
|
| 196 | - if (!empty($matches[$index + 2])) { |
|
| 197 | - $version .= '-dev'; |
|
| 198 | - } |
|
| 199 | - return $version; |
|
| 200 | - } |
|
| 201 | - $extraMessage = ''; |
|
| 202 | - if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
| 203 | - $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
| 204 | - } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
| 205 | - $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 206 | - } |
|
| 207 | - throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param string $stability |
|
| 212 | - */ |
|
| 213 | - private function expandStability($stability) { |
|
| 214 | - $stability = strtolower($stability); |
|
| 215 | - switch ($stability) { |
|
| 216 | - case 'a': |
|
| 217 | - return 'alpha'; |
|
| 218 | - case 'b': |
|
| 219 | - return 'beta'; |
|
| 220 | - case 'p': |
|
| 221 | - case 'pl': |
|
| 222 | - return 'patch'; |
|
| 223 | - case 'rc': |
|
| 224 | - return 'RC'; |
|
| 225 | - default: |
|
| 226 | - return $stability; |
|
| 227 | - } |
|
| 228 | - } |
|
| 33 | + public function __construct() { |
|
| 34 | + $this->packages = $this->initialize(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + protected function initialize() { |
|
| 38 | + $loadedExtensions = get_loaded_extensions(); |
|
| 39 | + $packages = array(); |
|
| 40 | + |
|
| 41 | + // Extensions scanning |
|
| 42 | + foreach ($loadedExtensions as $name) { |
|
| 43 | + if (in_array($name, array('standard', 'Core'))) { |
|
| 44 | + continue; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $ext = new \ReflectionExtension($name); |
|
| 48 | + try { |
|
| 49 | + $prettyVersion = $ext->getVersion(); |
|
| 50 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 51 | + } catch (\UnexpectedValueException $e) { |
|
| 52 | + $prettyVersion = '0'; |
|
| 53 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + foreach ($loadedExtensions as $name) { |
|
| 60 | + $prettyVersion = null; |
|
| 61 | + switch ($name) { |
|
| 62 | + case 'curl': |
|
| 63 | + $curlVersion = curl_version(); |
|
| 64 | + $prettyVersion = $curlVersion['version']; |
|
| 65 | + break; |
|
| 66 | + |
|
| 67 | + case 'iconv': |
|
| 68 | + $prettyVersion = ICONV_VERSION; |
|
| 69 | + break; |
|
| 70 | + |
|
| 71 | + case 'intl': |
|
| 72 | + $name = 'ICU'; |
|
| 73 | + if (defined('INTL_ICU_VERSION')) { |
|
| 74 | + $prettyVersion = INTL_ICU_VERSION; |
|
| 75 | + } else { |
|
| 76 | + $reflector = new \ReflectionExtension('intl'); |
|
| 77 | + |
|
| 78 | + ob_start(); |
|
| 79 | + $reflector->info(); |
|
| 80 | + $output = ob_get_clean(); |
|
| 81 | + |
|
| 82 | + preg_match('/^ICU version => (.*)$/m', $output, $matches); |
|
| 83 | + $prettyVersion = $matches[1]; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + break; |
|
| 87 | + |
|
| 88 | + case 'libxml': |
|
| 89 | + $prettyVersion = LIBXML_DOTTED_VERSION; |
|
| 90 | + break; |
|
| 91 | + |
|
| 92 | + case 'openssl': |
|
| 93 | + $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
| 94 | + return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
| 95 | + }, OPENSSL_VERSION_TEXT); |
|
| 96 | + break; |
|
| 97 | + |
|
| 98 | + case 'pcre': |
|
| 99 | + $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION); |
|
| 100 | + break; |
|
| 101 | + |
|
| 102 | + case 'uuid': |
|
| 103 | + $prettyVersion = phpversion('uuid'); |
|
| 104 | + break; |
|
| 105 | + |
|
| 106 | + case 'xsl': |
|
| 107 | + $prettyVersion = LIBXSLT_DOTTED_VERSION; |
|
| 108 | + break; |
|
| 109 | + |
|
| 110 | + default: |
|
| 111 | + // None handled extensions have no special cases, skip |
|
| 112 | + continue 2; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + try { |
|
| 116 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 117 | + } catch (\UnexpectedValueException $e) { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $packages; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + private function buildPackageName($name) { |
|
| 128 | + return str_replace(' ', '-', $name); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @param $name |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public function findLibrary($name) { |
|
| 136 | + $extName = $this->buildPackageName($name); |
|
| 137 | + if (isset($this->packages[$extName])) { |
|
| 138 | + return $this->packages[$extName]; |
|
| 139 | + } |
|
| 140 | + return null; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Normalizes a version string to be able to perform comparisons on it |
|
| 147 | + * |
|
| 148 | + * https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94 |
|
| 149 | + * |
|
| 150 | + * @param string $version |
|
| 151 | + * @param string $fullVersion optional complete version string to give more context |
|
| 152 | + * @throws \UnexpectedValueException |
|
| 153 | + * @return string |
|
| 154 | + */ |
|
| 155 | + public function normalizeVersion($version, $fullVersion = null) { |
|
| 156 | + $version = trim($version); |
|
| 157 | + if (null === $fullVersion) { |
|
| 158 | + $fullVersion = $version; |
|
| 159 | + } |
|
| 160 | + // ignore aliases and just assume the alias is required instead of the source |
|
| 161 | + if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) { |
|
| 162 | + $version = $match[1]; |
|
| 163 | + } |
|
| 164 | + // match master-like branches |
|
| 165 | + if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) { |
|
| 166 | + return '9999999-dev'; |
|
| 167 | + } |
|
| 168 | + if ('dev-' === strtolower(substr($version, 0, 4))) { |
|
| 169 | + return 'dev-' . substr($version, 4); |
|
| 170 | + } |
|
| 171 | + // match classical versioning |
|
| 172 | + if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 173 | + $version = $matches[1] |
|
| 174 | + . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 175 | + . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 176 | + . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 177 | + $index = 5; |
|
| 178 | + } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
| 179 | + $version = preg_replace('{\D}', '-', $matches[1]); |
|
| 180 | + $index = 2; |
|
| 181 | + } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 182 | + $version = $matches[1] |
|
| 183 | + . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 184 | + . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 185 | + . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 186 | + $index = 5; |
|
| 187 | + } |
|
| 188 | + // add version modifiers if a version was matched |
|
| 189 | + if (isset($index)) { |
|
| 190 | + if (!empty($matches[$index])) { |
|
| 191 | + if ('stable' === $matches[$index]) { |
|
| 192 | + return $version; |
|
| 193 | + } |
|
| 194 | + $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 195 | + } |
|
| 196 | + if (!empty($matches[$index + 2])) { |
|
| 197 | + $version .= '-dev'; |
|
| 198 | + } |
|
| 199 | + return $version; |
|
| 200 | + } |
|
| 201 | + $extraMessage = ''; |
|
| 202 | + if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
| 203 | + $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
| 204 | + } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
| 205 | + $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 206 | + } |
|
| 207 | + throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param string $stability |
|
| 212 | + */ |
|
| 213 | + private function expandStability($stability) { |
|
| 214 | + $stability = strtolower($stability); |
|
| 215 | + switch ($stability) { |
|
| 216 | + case 'a': |
|
| 217 | + return 'alpha'; |
|
| 218 | + case 'b': |
|
| 219 | + return 'beta'; |
|
| 220 | + case 'p': |
|
| 221 | + case 'pl': |
|
| 222 | + return 'patch'; |
|
| 223 | + case 'rc': |
|
| 224 | + return 'RC'; |
|
| 225 | + default: |
|
| 226 | + return $stability; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | } |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | break; |
| 91 | 91 | |
| 92 | 92 | case 'openssl': |
| 93 | - $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
| 94 | - return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
| 93 | + $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function($match) { |
|
| 94 | + return $match[1].(empty($match[2]) ? '' : '.'.(ord($match[2]) - 96)); |
|
| 95 | 95 | }, OPENSSL_VERSION_TEXT); |
| 96 | 96 | break; |
| 97 | 97 | |
@@ -166,19 +166,19 @@ discard block |
||
| 166 | 166 | return '9999999-dev'; |
| 167 | 167 | } |
| 168 | 168 | if ('dev-' === strtolower(substr($version, 0, 4))) { |
| 169 | - return 'dev-' . substr($version, 4); |
|
| 169 | + return 'dev-'.substr($version, 4); |
|
| 170 | 170 | } |
| 171 | 171 | // match classical versioning |
| 172 | - if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 172 | + if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.self::$modifierRegex.'$}i', $version, $matches)) { |
|
| 173 | 173 | $version = $matches[1] |
| 174 | 174 | . (!empty($matches[2]) ? $matches[2] : '.0') |
| 175 | 175 | . (!empty($matches[3]) ? $matches[3] : '.0') |
| 176 | 176 | . (!empty($matches[4]) ? $matches[4] : '.0'); |
| 177 | 177 | $index = 5; |
| 178 | - } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
| 178 | + } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)'.self::$modifierRegex.'$}i', $version, $matches)) { // match date-based versioning |
|
| 179 | 179 | $version = preg_replace('{\D}', '-', $matches[1]); |
| 180 | 180 | $index = 2; |
| 181 | - } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 181 | + } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?'.self::$modifierRegex.'$}i', $version, $matches)) { |
|
| 182 | 182 | $version = $matches[1] |
| 183 | 183 | . (!empty($matches[2]) ? $matches[2] : '.0') |
| 184 | 184 | . (!empty($matches[3]) ? $matches[3] : '.0') |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | if ('stable' === $matches[$index]) { |
| 192 | 192 | return $version; |
| 193 | 193 | } |
| 194 | - $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 194 | + $version .= '-'.$this->expandStability($matches[$index]).(!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 195 | 195 | } |
| 196 | 196 | if (!empty($matches[$index + 2])) { |
| 197 | 197 | $version .= '-dev'; |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | return $version; |
| 200 | 200 | } |
| 201 | 201 | $extraMessage = ''; |
| 202 | - if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
| 203 | - $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
| 204 | - } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
| 205 | - $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 202 | + if (preg_match('{ +as +'.preg_quote($version).'$}', $fullVersion)) { |
|
| 203 | + $extraMessage = ' in "'.$fullVersion.'", the alias must be an exact version'; |
|
| 204 | + } elseif (preg_match('{^'.preg_quote($version).' +as +}', $fullVersion)) { |
|
| 205 | + $extraMessage = ' in "'.$fullVersion.'", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 206 | 206 | } |
| 207 | - throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
| 207 | + throw new \UnexpectedValueException('Invalid version string "'.$version.'"'.$extraMessage); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | |
| 24 | 24 | //.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m) |
| 25 | 25 | class MSOffice2003 extends Office { |
| 26 | - /** |
|
| 27 | - * {@inheritDoc} |
|
| 28 | - */ |
|
| 29 | - public function getMimeType() { |
|
| 30 | - return '/application\/vnd.ms-.*/'; |
|
| 31 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritDoc} |
|
| 28 | + */ |
|
| 29 | + public function getMimeType() { |
|
| 30 | + return '/application\/vnd.ms-.*/'; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -28,41 +28,41 @@ |
||
| 28 | 28 | use OCP\Preview\IProvider; |
| 29 | 29 | |
| 30 | 30 | abstract class Provider implements IProvider { |
| 31 | - private $options; |
|
| 31 | + private $options; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor |
|
| 35 | - * |
|
| 36 | - * @param array $options |
|
| 37 | - */ |
|
| 38 | - public function __construct(array $options = []) { |
|
| 39 | - $this->options = $options; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor |
|
| 35 | + * |
|
| 36 | + * @param array $options |
|
| 37 | + */ |
|
| 38 | + public function __construct(array $options = []) { |
|
| 39 | + $this->options = $options; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string Regex with the mimetypes that are supported by this provider |
|
| 44 | - */ |
|
| 45 | - abstract public function getMimeType(); |
|
| 42 | + /** |
|
| 43 | + * @return string Regex with the mimetypes that are supported by this provider |
|
| 44 | + */ |
|
| 45 | + abstract public function getMimeType(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Check if a preview can be generated for $path |
|
| 49 | - * |
|
| 50 | - * @param \OCP\Files\FileInfo $file |
|
| 51 | - * @return bool |
|
| 52 | - */ |
|
| 53 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 54 | - return true; |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Check if a preview can be generated for $path |
|
| 49 | + * |
|
| 50 | + * @param \OCP\Files\FileInfo $file |
|
| 51 | + * @return bool |
|
| 52 | + */ |
|
| 53 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 54 | + return true; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
| 59 | - * |
|
| 60 | - * @param string $path Path of file |
|
| 61 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 62 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 63 | - * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 64 | - * @param \OC\Files\View $fileview fileview object of user folder |
|
| 65 | - * @return bool|\OCP\IImage false if no preview was generated |
|
| 66 | - */ |
|
| 67 | - abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 57 | + /** |
|
| 58 | + * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
| 59 | + * |
|
| 60 | + * @param string $path Path of file |
|
| 61 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 62 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 63 | + * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 64 | + * @param \OC\Files\View $fileview fileview object of user folder |
|
| 65 | + * @return bool|\OCP\IImage false if no preview was generated |
|
| 66 | + */ |
|
| 67 | + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 68 | 68 | } |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | |
| 24 | 24 | //.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt |
| 25 | 25 | class OpenDocument extends Office { |
| 26 | - /** |
|
| 27 | - * {@inheritDoc} |
|
| 28 | - */ |
|
| 29 | - public function getMimeType() { |
|
| 30 | - return '/application\/vnd.oasis.opendocument.*/'; |
|
| 31 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritDoc} |
|
| 28 | + */ |
|
| 29 | + public function getMimeType() { |
|
| 30 | + return '/application\/vnd.oasis.opendocument.*/'; |
|
| 31 | + } |
|
| 32 | 32 | } |