From 5d9b56d194c4dcfc285b38bfc3e5693544d44431 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 2 Mar 2018 23:59:35 +0700 Subject: [PATCH 01/28] Replaced func_get_args() by ...$params (PHP 5.6+). --- src/PHPCensor/Builder.php | 6 ++++-- src/PHPCensor/Helper/Lang.php | 24 +++++++++++++----------- tests/bootstrap.php | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 5cbe6778..896c2e59 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -278,11 +278,13 @@ class Builder implements LoggerAwareInterface /** * Used by this class, and plugins, to execute shell commands. * + * @param array ...$params + * * @return boolean */ - public function executeCommand() + public function executeCommand(...$params) { - return $this->commandExecutor->executeCommand(func_get_args()); + return $this->commandExecutor->executeCommand($params); } /** diff --git a/src/PHPCensor/Helper/Lang.php b/src/PHPCensor/Helper/Lang.php index 300ee1b4..5c452942 100644 --- a/src/PHPCensor/Helper/Lang.php +++ b/src/PHPCensor/Helper/Lang.php @@ -37,19 +37,19 @@ class Lang /** * Get a specific string from the language file. * - * @param $string - * @return mixed|string + * @param string $string + * @param array ...$params + * + * @return string */ - public static function get($string) + public static function get($string, ...$params) { - $vars = func_get_args(); - if (array_key_exists($string, self::$strings)) { - $vars[0] = self::$strings[$string]; - return call_user_func_array('sprintf', $vars); + $params[0] = self::$strings[$string]; + return call_user_func_array('sprintf', $params); } elseif (self::DEFAULT_LANGUAGE !== self::$language && array_key_exists($string, self::$default_strings)) { - $vars[0] = self::$default_strings[$string]; - return call_user_func_array('sprintf', $vars); + $params[0] = self::$default_strings[$string]; + return call_user_func_array('sprintf', $params); } return $string; @@ -57,10 +57,12 @@ class Lang /** * Output a specific string from the language file. + * + * @param array ...$params */ - public static function out() + public static function out(...$params) { - print call_user_func_array(['PHPCensor\Helper\Lang', 'get'], func_get_args()); + print call_user_func_array(['PHPCensor\Helper\Lang', 'get'], $params); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 113bf8bf..d07365a4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -35,7 +35,7 @@ $conf['php-censor']['url'] = 'http://php-censor.local'; $config = new b8\Config($conf); -if (!defined('APP_URL') && !empty($config)) { +if (!defined('APP_URL')) { define('APP_URL', $config->get('php-censor.url', '') . '/'); } From 8dc1e8e8578b7903972009f50879a82930e337b2 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 3 Mar 2018 12:49:50 +0700 Subject: [PATCH 02/28] Added symfony/var-dumper component to the require-dev dependency and updated dependencies. --- composer.json | 5 +- composer.lock | 204 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 140 insertions(+), 69 deletions(-) diff --git a/composer.json b/composer.json index 75966be4..111af7df 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,6 @@ "symfony/browser-kit": "~3.4.0", "symfony/process": "~3.4.0", "symfony/filesystem": "~3.4.0", - "symfony/debug": "~3.4.0", "symfony/dependency-injection": "~3.4.0", "symfony/event-dispatcher": "~3.4.0", "symfony/cache": "~3.4.0", @@ -85,6 +84,7 @@ "jakub-onderka/php-parallel-lint": "~0.9.0", "sensiolabs/security-checker": "~4.0.0", + "symfony/debug": "~3.4.0", "doctrine/instantiator": "~1.0.0", "phpunit/php-token-stream": "~1.4.0", "phpdocumentor/reflection-docblock": "~2.0.0", @@ -99,7 +99,8 @@ "bower-asset/raphael": "~2.2.0" }, "require-dev": { - "phpunit/dbunit": "~2.0.0" + "phpunit/dbunit": "~2.0.0", + "symfony/var-dumper": "~3.4.0" }, "suggest": { "maknz/slack": "For SlackNotify plugin", diff --git a/composer.lock b/composer.lock index 6999424c..823538ba 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "86960b0e8aee816f39921ca1c3e6bfc3", + "content-hash": "88f485bcc21591dbaf905423dc70d835", "packages": [ { "name": "behat/gherkin", @@ -1025,16 +1025,16 @@ }, { "name": "nikic/php-parser", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078" + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/e57b3a09784f846411aa7ed664eedb73e3399078", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", "shasum": "" }, "require": { @@ -1072,7 +1072,7 @@ "parser", "php" ], - "time": "2018-01-25T21:31:33+00:00" + "time": "2018-02-28T20:30:58+00:00" }, { "name": "npm-asset/codemirror", @@ -3029,7 +3029,7 @@ }, { "name": "symfony/browser-kit", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", @@ -3086,16 +3086,16 @@ }, { "name": "symfony/cache", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", - "reference": "8dee9ec2c9824c3f4039960d679a6689ee1cbdc1" + "reference": "cce49c7aa2fc82077355c8a6dfcd9e619abe6e98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/8dee9ec2c9824c3f4039960d679a6689ee1cbdc1", - "reference": "8dee9ec2c9824c3f4039960d679a6689ee1cbdc1", + "url": "https://api.github.com/repos/symfony/cache/zipball/cce49c7aa2fc82077355c8a6dfcd9e619abe6e98", + "reference": "cce49c7aa2fc82077355c8a6dfcd9e619abe6e98", "shasum": "" }, "require": { @@ -3152,20 +3152,20 @@ "caching", "psr6" ], - "time": "2018-01-18T22:16:57+00:00" + "time": "2018-02-11T14:42:07+00:00" }, { "name": "symfony/config", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "72689b934d6c6ecf73eca874e98933bf055313c9" + "reference": "05e10567b529476a006b00746c5f538f1636810e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/72689b934d6c6ecf73eca874e98933bf055313c9", - "reference": "72689b934d6c6ecf73eca874e98933bf055313c9", + "url": "https://api.github.com/repos/symfony/config/zipball/05e10567b529476a006b00746c5f538f1636810e", + "reference": "05e10567b529476a006b00746c5f538f1636810e", "shasum": "" }, "require": { @@ -3178,6 +3178,7 @@ }, "require-dev": { "symfony/dependency-injection": "~3.3|~4.0", + "symfony/event-dispatcher": "~3.3|~4.0", "symfony/finder": "~3.3|~4.0", "symfony/yaml": "~3.0|~4.0" }, @@ -3214,20 +3215,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2018-01-21T19:05:02+00:00" + "time": "2018-02-14T10:03:57+00:00" }, { "name": "symfony/console", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "26b6f419edda16c19775211987651cb27baea7f1" + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/26b6f419edda16c19775211987651cb27baea7f1", - "reference": "26b6f419edda16c19775211987651cb27baea7f1", + "url": "https://api.github.com/repos/symfony/console/zipball/067339e9b8ec30d5f19f5950208893ff026b94f7", + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7", "shasum": "" }, "require": { @@ -3283,20 +3284,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-26T15:46:28+00:00" }, { "name": "symfony/css-selector", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "e66394bc7610e69279bfdb3ab11b4fe65403f556" + "reference": "544655f1fc078a9cd839fdda2b7b1e64627c826a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/e66394bc7610e69279bfdb3ab11b4fe65403f556", - "reference": "e66394bc7610e69279bfdb3ab11b4fe65403f556", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/544655f1fc078a9cd839fdda2b7b1e64627c826a", + "reference": "544655f1fc078a9cd839fdda2b7b1e64627c826a", "shasum": "" }, "require": { @@ -3336,20 +3337,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-02-03T14:55:07+00:00" }, { "name": "symfony/debug", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "53f6af2805daf52a43b393b93d2f24925d35c937" + "reference": "9b1071f86e79e1999b3d3675d2e0e7684268b9bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/53f6af2805daf52a43b393b93d2f24925d35c937", - "reference": "53f6af2805daf52a43b393b93d2f24925d35c937", + "url": "https://api.github.com/repos/symfony/debug/zipball/9b1071f86e79e1999b3d3675d2e0e7684268b9bc", + "reference": "9b1071f86e79e1999b3d3675d2e0e7684268b9bc", "shasum": "" }, "require": { @@ -3392,20 +3393,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2018-01-18T22:16:57+00:00" + "time": "2018-02-28T21:49:22+00:00" }, { "name": "symfony/dependency-injection", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "4b2717ee2499390e371e1fc7abaf886c1c83e83d" + "reference": "752c45dc831dc42a472f0ab8ae0450b63b840656" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/4b2717ee2499390e371e1fc7abaf886c1c83e83d", - "reference": "4b2717ee2499390e371e1fc7abaf886c1c83e83d", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/752c45dc831dc42a472f0ab8ae0450b63b840656", + "reference": "752c45dc831dc42a472f0ab8ae0450b63b840656", "shasum": "" }, "require": { @@ -3463,20 +3464,20 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:16:57+00:00" + "time": "2018-02-26T14:27:04+00:00" }, { "name": "symfony/dom-crawler", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "09bd97b844b3151fab82f2fdd62db9c464b3910a" + "reference": "2bb5d3101cc01f4fe580e536daf4f1959bc2d24d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/09bd97b844b3151fab82f2fdd62db9c464b3910a", - "reference": "09bd97b844b3151fab82f2fdd62db9c464b3910a", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/2bb5d3101cc01f4fe580e536daf4f1959bc2d24d", + "reference": "2bb5d3101cc01f4fe580e536daf4f1959bc2d24d", "shasum": "" }, "require": { @@ -3519,20 +3520,20 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-02-22T10:48:49+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "26b87b6bca8f8f797331a30b76fdae5342dc26ca" + "reference": "58990682ac3fdc1f563b7e705452921372aad11d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/26b87b6bca8f8f797331a30b76fdae5342dc26ca", - "reference": "26b87b6bca8f8f797331a30b76fdae5342dc26ca", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/58990682ac3fdc1f563b7e705452921372aad11d", + "reference": "58990682ac3fdc1f563b7e705452921372aad11d", "shasum": "" }, "require": { @@ -3582,20 +3583,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-02-14T10:03:57+00:00" }, { "name": "symfony/filesystem", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "e078773ad6354af38169faf31c21df0f18ace03d" + "reference": "253a4490b528597aa14d2bf5aeded6f5e5e4a541" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/e078773ad6354af38169faf31c21df0f18ace03d", - "reference": "e078773ad6354af38169faf31c21df0f18ace03d", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/253a4490b528597aa14d2bf5aeded6f5e5e4a541", + "reference": "253a4490b528597aa14d2bf5aeded6f5e5e4a541", "shasum": "" }, "require": { @@ -3631,20 +3632,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-02-22T10:48:49+00:00" }, { "name": "symfony/finder", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "613e26310776f49a1773b6737c6bd554b8bc8c6f" + "reference": "6a615613745cef820d807443f32076bb9f5d0a38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/613e26310776f49a1773b6737c6bd554b8bc8c6f", - "reference": "613e26310776f49a1773b6737c6bd554b8bc8c6f", + "url": "https://api.github.com/repos/symfony/finder/zipball/6a615613745cef820d807443f32076bb9f5d0a38", + "reference": "6a615613745cef820d807443f32076bb9f5d0a38", "shasum": "" }, "require": { @@ -3680,7 +3681,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-02-11T17:15:12+00:00" }, { "name": "symfony/polyfill-apcu", @@ -3799,16 +3800,16 @@ }, { "name": "symfony/process", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "09a5172057be8fc677840e591b17f385e58c7c0d" + "reference": "cc4aea21f619116aaf1c58016a944e4821c8e8af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/09a5172057be8fc677840e591b17f385e58c7c0d", - "reference": "09a5172057be8fc677840e591b17f385e58c7c0d", + "url": "https://api.github.com/repos/symfony/process/zipball/cc4aea21f619116aaf1c58016a944e4821c8e8af", + "reference": "cc4aea21f619116aaf1c58016a944e4821c8e8af", "shasum": "" }, "require": { @@ -3844,20 +3845,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-12T17:55:00+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "eab73b6c21d27ae4cd037c417618dfd4befb0bfe" + "reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/eab73b6c21d27ae4cd037c417618dfd4befb0bfe", - "reference": "eab73b6c21d27ae4cd037c417618dfd4befb0bfe", + "url": "https://api.github.com/repos/symfony/yaml/zipball/6af42631dcf89e9c616242c900d6c52bd53bd1bb", + "reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb", "shasum": "" }, "require": { @@ -3902,7 +3903,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-01-21T19:05:02+00:00" + "time": "2018-02-16T09:50:28+00:00" }, { "name": "theseer/fdomdocument", @@ -4000,6 +4001,75 @@ "xunit" ], "time": "2016-12-02T14:39:14+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v3.4.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "80964679d81da3d5618519e0e4be488c3d7ecd7d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/80964679d81da3d5618519e0e4be488c3d7ecd7d", + "reference": "80964679d81da3d5618519e0e4be488c3d7ecd7d", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0" + }, + "require-dev": { + "ext-iconv": "*", + "twig/twig": "~1.34|~2.4" + }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "ext-symfony_debug": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony mechanism for exploring and dumping PHP variables", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "time": "2018-02-22T17:29:24+00:00" } ], "aliases": [], From 905d6d41d13875d20e95f0d990f1d7b236b29333 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 00:27:48 +0700 Subject: [PATCH 03/28] Refactored models. --- src/B8Framework/Model.php | 194 ------------------ src/B8Framework/Store.php | 2 + src/PHPCensor/Helper/Lang.php | 4 +- src/PHPCensor/Model.php | 145 ++++++++++++- src/PHPCensor/Model/Build.php | 114 +++++----- src/PHPCensor/Model/BuildError.php | 91 +++----- src/PHPCensor/Model/BuildMeta.php | 61 +----- src/PHPCensor/Model/Environment.php | 12 +- src/PHPCensor/Model/Project.php | 108 +++------- src/PHPCensor/Model/ProjectGroup.php | 18 +- src/PHPCensor/Model/User.php | 24 +-- src/PHPCensor/Service/BuildService.php | 20 +- src/PHPCensor/Service/ProjectService.php | 2 +- .../WidgetAllProjects/index-projects.phtml | 4 +- .../View/WidgetAllProjects/update.phtml | 4 +- .../View/WidgetBuildErrors/update.phtml | 4 +- tests/B8Framework/FormTest.php | 5 +- tests/PHPCensor/Helper/LangTest.php | 43 ---- tests/PHPCensor/LocalizationTestCase.php | 24 --- tests/PHPCensor/Model/BuildTest.php | 67 +++++- tests/PHPCensor/Model/ProjectTest.php | 1 - tests/PHPCensor/Service/BuildServiceTest.php | 2 +- .../Service/BuiltStatusServiceTest.php | 2 +- 23 files changed, 369 insertions(+), 582 deletions(-) delete mode 100644 src/B8Framework/Model.php delete mode 100644 tests/PHPCensor/Helper/LangTest.php delete mode 100644 tests/PHPCensor/LocalizationTestCase.php diff --git a/src/B8Framework/Model.php b/src/B8Framework/Model.php deleted file mode 100644 index 7c0784ca..00000000 --- a/src/B8Framework/Model.php +++ /dev/null @@ -1,194 +0,0 @@ -data = array_merge($this->data, $initialData); - } - - $this->cache = new ArrayCache(); - } - - /** - * @return string - */ - public function getTableName() - { - return $this->tableName; - } - - /** - * @return array - */ - public function getDataArray() - { - return $this->data; - } - - /** - * @return array - */ - public function getModified() - { - return $this->modified; - } - - /** - * @param array $values - */ - public function setValues(array $values) - { - foreach ($values as $key => $value) { - if (isset($this->setters[$key])) { - $func = $this->setters[$key]; - - if ($value === 'null') { - $value = null; - } elseif ($value === 'true') { - $value = true; - } elseif ($value === 'false') { - $value = false; - } - - $this->{$func}($value); - } - } - } - - /** - * @param string $column - */ - protected function setModified($column) - { - $this->modified[$column] = $column; - } - - /** - * @param string $name - * @param mixed $value - * - * @throws HttpException\ValidationException - */ - protected function validateString($name, $value) - { - if (!is_string($value) && !is_null($value)) { - throw new HttpException\ValidationException('Column "', $name . '" must be a string.'); - } - } - - /** - * @param string $name - * @param mixed $value - * - * @throws HttpException\ValidationException - */ - protected function validateInt($name, &$value) - { - if (is_bool($value)) { - $value = $value ? 1 : 0; - } - - if (!is_numeric($value) && !is_null($value)) { - throw new HttpException\ValidationException('Column "', $name . '" must be an integer.'); - } - - if (!is_int($value) && !is_null($value)) { - $value = (int)$value; - } - } - - /** - * @param string $name - * @param mixed $value - * - * @throws HttpException\ValidationException - */ - protected function validateFloat($name, &$value) - { - if (!is_numeric($value) && !is_null($value)) { - throw new HttpException\ValidationException('Column "', $name . '" must be a float.'); - } - - if (!is_float($value) && !is_null($value)) { - $value = (float)$value; - } - } - - /** - * @param string $name - * @param mixed $value - * - * @throws HttpException\ValidationException - */ - protected function validateDate($name, &$value) - { - if (is_string($value)) { - $value = empty($value) ? null : new \DateTime($value); - } - - if ((!is_object($value) || !($value instanceof \DateTime)) && !is_null($value)) { - throw new HttpException\ValidationException('Column "', $name . '" must be a date object.'); - } - - $value = empty($value) ? null : $value->format('Y-m-d H:i:s'); - } - - /** - * @param string $name - * @param mixed $value - * - * @throws HttpException\ValidationException - */ - protected function validateNotNull($name, $value) - { - if (is_null($value)) { - throw new HttpException\ValidationException('Column "', $name . '" must not be null.'); - } - } - - /** - * @param string $key - * - * @return mixed - */ - public function __get($key) - { - if (array_key_exists($key, $this->getters)) { - $getter = $this->getters[$key]; - return $this->{$getter}(); - } - - return null; - } - - /** - * @param string $key - * @param mixed $value - * - * @return mixed - */ - public function __set($key, $value) - { - if (array_key_exists($key, $this->setters)) { - $setter = $this->setters[$key]; - return $this->{$setter}($value); - } - } -} diff --git a/src/B8Framework/Store.php b/src/B8Framework/Store.php index bef8e11a..19e36977 100644 --- a/src/B8Framework/Store.php +++ b/src/B8Framework/Store.php @@ -2,6 +2,8 @@ namespace b8; +use PHPCensor\Model; + abstract class Store { /** diff --git a/src/PHPCensor/Helper/Lang.php b/src/PHPCensor/Helper/Lang.php index 5c452942..0e340a02 100644 --- a/src/PHPCensor/Helper/Lang.php +++ b/src/PHPCensor/Helper/Lang.php @@ -37,13 +37,13 @@ class Lang /** * Get a specific string from the language file. * - * @param string $string * @param array ...$params * * @return string */ - public static function get($string, ...$params) + public static function get(...$params) { + $string = $params[0]; if (array_key_exists($string, self::$strings)) { $params[0] = self::$strings[$string]; return call_user_func_array('sprintf', $params); diff --git a/src/PHPCensor/Model.php b/src/PHPCensor/Model.php index b11c4ada..e7c485fc 100644 --- a/src/PHPCensor/Model.php +++ b/src/PHPCensor/Model.php @@ -2,6 +2,149 @@ namespace PHPCensor; -abstract class Model extends \b8\Model +use b8\Exception\HttpException; + +class Model { + /** + * @var array + */ + protected $getters = []; + + /** + * @var array + */ + protected $setters = []; + + /** + * @var array + */ + protected $data = []; + + /** + * @var array + */ + protected $modified = []; + + /** + * @var string + */ + protected $tableName; + + /** + * @param array $initialData + */ + public function __construct($initialData = []) + { + if (is_array($initialData)) { + foreach ($initialData as $index => $item) { + if (!array_key_exists($index, $this->data)) { + throw new \InvalidArgumentException(sprintf( + 'Model "%s" doesn\'t have field "%s"', + get_called_class(), + $index + )); + } + + $this->data[$index] = $item; + } + } + } + + /** + * @return string + */ + public function getTableName() + { + return $this->tableName; + } + + /** + * @return array + */ + public function getDataArray() + { + return $this->data; + } + + /** + * @return array + */ + public function getModified() + { + return $this->modified; + } + + /** + * @param string $column + */ + protected function setModified($column) + { + $this->modified[$column] = $column; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws HttpException\ValidationException + */ + protected function validateString($name, $value) + { + if (!is_string($value) && !is_null($value)) { + throw new HttpException\ValidationException('Column "' . $name . '" must be a string.'); + } + } + + /** + * @param string $name + * @param mixed $value + * + * @throws HttpException\ValidationException + */ + protected function validateInt($name, $value) + { + if (!is_integer($value) && !is_null($value)) { + throw new HttpException\ValidationException('Column "' . $name . '" must be an integer.'); + } + } + + /** + * @param string $name + * @param mixed $value + * + * @throws HttpException\ValidationException + */ + protected function validateFloat($name, $value) + { + if (!is_float($value) && !is_null($value)) { + throw new HttpException\ValidationException('Column "' . $name . '" must be a float.'); + } + } + + /** + * @param string $name + * @param mixed $value + * + * @throws HttpException\ValidationException + */ + protected function validateDate($name, $value) + { + if (!($value instanceof \DateTime) && !is_null($value)) { + throw new HttpException\ValidationException('Column "', $name . '" must be a date object.'); + } + } + + /** + * @param string $name + * @param mixed $value + * + * @throws HttpException\ValidationException + */ + protected function validateNotNull($name, $value) + { + if (is_null($value)) { + throw new HttpException\ValidationException('Column "', $name . '" must not be null.'); + } + } } diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index ba443e78..4490303a 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -124,9 +124,6 @@ class Build extends Model 'environment' => 'setEnvironment', 'source' => 'setSource', 'user_id' => 'setUserId', - - // Foreign key setters: - 'Project' => 'setProject', ]; /** @@ -140,7 +137,7 @@ class Build extends Model } /** - * @param $value int + * @param integer $value */ public function setId($value) { @@ -167,7 +164,7 @@ class Build extends Model } /** - * @param $value int + * @param integer $value */ public function setProjectId($value) { @@ -194,7 +191,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setCommitId($value) { @@ -221,7 +218,7 @@ class Build extends Model } /** - * @param $value int + * @param integer $value */ public function setStatus($value) { @@ -248,7 +245,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setLog($value) { @@ -274,7 +271,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setBranch($value) { @@ -305,17 +302,19 @@ class Build extends Model } /** - * @param $value \DateTime + * @param \DateTime $value */ - public function setCreateDate($value) + public function setCreateDate(\DateTime $value) { $this->validateDate('create_date', $value); - if ($this->data['create_date'] === $value) { + $stringValue = $value->format('Y-m-d H:i:s'); + + if ($this->data['create_date'] === $stringValue) { return; } - $this->data['create_date'] = $value; + $this->data['create_date'] = $stringValue; $this->setModified('create_date'); } @@ -335,17 +334,19 @@ class Build extends Model } /** - * @param $value \DateTime + * @param \DateTime $value */ - public function setStartDate($value) + public function setStartDate(\DateTime $value) { $this->validateDate('start_date', $value); - if ($this->data['start_date'] === $value) { + $stringValue = $value->format('Y-m-d H:i:s'); + + if ($this->data['start_date'] === $stringValue) { return; } - $this->data['start_date'] = $value; + $this->data['start_date'] = $stringValue; $this->setModified('start_date'); } @@ -365,17 +366,19 @@ class Build extends Model } /** - * @param $value \DateTime + * @param \DateTime $value */ - public function setFinishDate($value) + public function setFinishDate(\DateTime $value) { $this->validateDate('finish_date', $value); - if ($this->data['finish_date'] === $value) { + $stringValue = $value->format('Y-m-d H:i:s'); + + if ($this->data['finish_date'] === $stringValue) { return; } - $this->data['finish_date'] = $value; + $this->data['finish_date'] = $stringValue; $this->setModified('finish_date'); } @@ -391,7 +394,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setCommitterEmail($value) { @@ -417,7 +420,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setCommitMessage($value) { @@ -443,7 +446,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setTag($value) { @@ -469,7 +472,7 @@ class Build extends Model } /** - * @param $value integer + * @param integer $value */ public function setSource($value) { @@ -495,7 +498,7 @@ class Build extends Model } /** - * @param $value integer + * @param integer $value */ public function setUserId($value) { @@ -522,7 +525,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setEnvironment($value) { @@ -540,8 +543,9 @@ class Build extends Model /** * Set the value of status only if it synced with db. Must not be null. * - * @param $value int - * @return bool + * @param integer $value + * + * @return boolean */ public function setStatusSync($value) { @@ -561,9 +565,9 @@ class Build extends Model /** * Return a value from the build's "extra" JSON array. * - * @param null $key + * @param string|null $key * - * @return mixed|null|string + * @return array|string|null */ public function getExtra($key = null) { @@ -581,7 +585,7 @@ class Build extends Model } /** - * @param $value string + * @param string $value */ public function setExtra($value) { @@ -599,8 +603,8 @@ class Build extends Model /** * Set the value of extra. * - * @param $name string - * @param $value mixed + * @param string $name + * @param mixed $value */ public function setExtraValue($name, $value) { @@ -615,7 +619,7 @@ class Build extends Model /** * Set the values of extra. * - * @param $values mixed + * @param mixed $values */ public function setExtraValues($values) { @@ -643,37 +647,6 @@ class Build extends Model return Factory::getStore('Project', 'PHPCensor')->getById($key); } - /** - * Set Project - Accepts an ID, an array representing a Project or a Project model. - * - * @param $value mixed - */ - public function setProject($value) - { - // Is this an instance of Project? - if ($value instanceof Project) { - return $this->setProjectObject($value); - } - - // Is this an array representing a Project item? - if (is_array($value) && !empty($value['id'])) { - return $this->setProjectId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setProjectId($value); - } - - /** - * Set Project - Accepts a Project model. - * - * @param $value Project - */ - public function setProjectObject(Project $value) - { - return $this->setProjectId($value->getId()); - } - /** * Get BuildError models by BuildId for this Build. * @@ -763,6 +736,9 @@ class Build extends Model /** * Store build metadata + * + * @param string $key + * @param string $value */ public function storeMeta($key, $value) { @@ -813,7 +789,9 @@ class Build extends Model /** * Get an array of plugins to run if there's no .php-censor.yml file. + * * @param Builder $builder + * * @return array */ protected function getZeroConfigPlugins(Builder $builder) @@ -982,7 +960,7 @@ class Build extends Model /** * Get the number of seconds a build has been running for. * - * @return int + * @return integer */ public function getDuration() { @@ -1044,7 +1022,7 @@ class Build extends Model /** * Create an SSH key file on disk for this build. * - * @param string $cloneTo + * @param string $cloneTo * * @return string */ diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index a031b395..ba9ff575 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -71,13 +71,10 @@ class BuildError extends Model 'create_date' => 'setCreateDate', 'hash' => 'setHash', 'is_new' => 'setIsNew', - - // Foreign key setters: - 'Build' => 'setBuild', ]; /** - * @return int + * @return integer */ public function getId() { @@ -87,7 +84,7 @@ class BuildError extends Model } /** - * @return int + * @return integer */ public function getBuildId() { @@ -117,7 +114,7 @@ class BuildError extends Model } /** - * @return int + * @return integer */ public function getLineStart() { @@ -127,7 +124,7 @@ class BuildError extends Model } /** - * @return int + * @return integer */ public function getLineEnd() { @@ -137,7 +134,7 @@ class BuildError extends Model } /** - * @return int + * @return integer */ public function getSeverity() { @@ -191,7 +188,7 @@ class BuildError extends Model } /** - * @param $value int + * @param integer $value */ public function setId($value) { @@ -208,7 +205,7 @@ class BuildError extends Model } /** - * @param $value int + * @param integer $value */ public function setBuildId($value) { @@ -225,7 +222,7 @@ class BuildError extends Model } /** - * @param $value string + * @param string $value */ public function setPlugin($value) { @@ -242,7 +239,7 @@ class BuildError extends Model } /** - * @param $value string + * @param string $value */ public function setFile($value) { @@ -258,7 +255,7 @@ class BuildError extends Model } /** - * @param $value int + * @param integer $value */ public function setLineStart($value) { @@ -274,7 +271,7 @@ class BuildError extends Model } /** - * @param $value int + * @param integer $value */ public function setLineEnd($value) { @@ -290,7 +287,7 @@ class BuildError extends Model } /** - * @param $value int + * @param integer $value */ public function setSeverity($value) { @@ -307,7 +304,7 @@ class BuildError extends Model } /** - * @param $value string + * @param string $value */ public function setMessage($value) { @@ -324,24 +321,26 @@ class BuildError extends Model } /** - * @param $value \DateTime + * @param \DateTime $value */ - public function setCreateDate($value) + public function setCreateDate(\DateTime $value) { $this->validateNotNull('create_date', $value); $this->validateDate('create_date', $value); - if ($this->data['create_date'] === $value) { + $stringValue = $value->format('Y-m-d H:i:s'); + + if ($this->data['create_date'] === $stringValue) { return; } - $this->data['create_date'] = $value; + $this->data['create_date'] = $stringValue; $this->setModified('create_date'); } /** - * @param $value string + * @param string $value */ public function setHash($value) { @@ -358,7 +357,7 @@ class BuildError extends Model } /** - * @param $value int + * @param integer $value */ public function setIsNew($value) { @@ -377,56 +376,16 @@ class BuildError extends Model /** * Get the Build model for this BuildError by Id. * - * @return \PHPCensor\Model\Build + * @return \PHPCensor\Model\Build|null */ public function getBuild() { - $key = $this->getBuildId(); - - if (empty($key)) { + $buildId = $this->getBuildId(); + if (empty($buildId)) { return null; } - $cacheKey = 'php-censor.build-' . $key; - $rtn = $this->cache->get($cacheKey); - - if (empty($rtn)) { - $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Build - Accepts an ID, an array representing a Build or a Build model. - * - * @param $value mixed - */ - public function setBuild($value) - { - // Is this an instance of Build? - if ($value instanceof Build) { - return $this->setBuildObject($value); - } - - // Is this an array representing a Build item? - if (is_array($value) && !empty($value['id'])) { - return $this->setBuildId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setBuildId($value); - } - - /** - * Set Build - Accepts a Build model. - * - * @param $value Build - */ - public function setBuildObject(Build $value) - { - return $this->setBuildId($value->getId()); + return Factory::getStore('Build', 'PHPCensor')->getById($buildId); } /** diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index f1bd45c4..0ec7fdb5 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -45,13 +45,10 @@ class BuildMeta extends Model 'build_id' => 'setBuildId', 'meta_key' => 'setMetaKey', 'meta_value' => 'setMetaValue', - - // Foreign key setters: - 'Build' => 'setBuild', ]; /** - * @return int + * @return integer */ public function getId() { @@ -61,7 +58,7 @@ class BuildMeta extends Model } /** - * @return int + * @return integer */ public function getBuildId() { @@ -91,7 +88,7 @@ class BuildMeta extends Model } /** - * @param int $value + * @param integer $value */ public function setId($value) { @@ -108,7 +105,7 @@ class BuildMeta extends Model } /** - * @param int $value + * @param integer $value */ public function setBuildId($value) { @@ -125,7 +122,7 @@ class BuildMeta extends Model } /** - * @param $value string + * @param string $value */ public function setMetaKey($value) { @@ -142,7 +139,7 @@ class BuildMeta extends Model } /** - * @param $value string + * @param string $value */ public function setMetaValue($value) { @@ -165,51 +162,11 @@ class BuildMeta extends Model */ public function getBuild() { - $key = $this->getBuildId(); - - if (empty($key)) { + $buildId = $this->getBuildId(); + if (empty($buildId)) { return null; } - $cacheKey = 'php-censor.build-' . $key; - $rtn = $this->cache->get($cacheKey); - - if (empty($rtn)) { - $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Build - Accepts an ID, an array representing a Build or a Build model. - * - * @param $value mixed - */ - public function setBuild($value) - { - // Is this an instance of Build? - if ($value instanceof Build) { - return $this->setBuildObject($value); - } - - // Is this an array representing a Build item? - if (is_array($value) && !empty($value['id'])) { - return $this->setBuildId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setBuildId($value); - } - - /** - * Set Build - Accepts a Build model. - * - * @param $value Build - */ - public function setBuildObject(Build $value) - { - return $this->setBuildId($value->getId()); + return Factory::getStore('Build', 'PHPCensor')->getById($buildId); } } diff --git a/src/PHPCensor/Model/Environment.php b/src/PHPCensor/Model/Environment.php index 427a9be8..ade80d6e 100644 --- a/src/PHPCensor/Model/Environment.php +++ b/src/PHPCensor/Model/Environment.php @@ -42,7 +42,7 @@ class Environment extends Model ]; /** - * @return int + * @return integer */ public function getId() { @@ -52,7 +52,7 @@ class Environment extends Model } /** - * @return int + * @return integer */ public function getProjectId() { @@ -82,7 +82,7 @@ class Environment extends Model } /** - * @param $value int + * @param integer $value */ public function setId($value) { @@ -99,7 +99,7 @@ class Environment extends Model } /** - * @param $value int + * @param integer $value */ public function setProjectId($value) { @@ -116,7 +116,7 @@ class Environment extends Model } /** - * @param $value string + * @param string $value */ public function setName($value) { @@ -133,7 +133,7 @@ class Environment extends Model } /** - * @param $value array + * @param array $value */ public function setBranches($value) { diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 58240261..688838b6 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -94,7 +94,7 @@ class Project extends Model ]; /** - * @return int + * @return integer */ public function getId() { @@ -174,7 +174,7 @@ class Project extends Model } /** - * @return int + * @return integer */ public function getAllowPublicStatus() { @@ -184,7 +184,7 @@ class Project extends Model } /** - * @return int + * @return integer */ public function getArchived() { @@ -194,7 +194,7 @@ class Project extends Model } /** - * @return int + * @return integer */ public function getGroupId() { @@ -204,7 +204,7 @@ class Project extends Model } /** - * @return int + * @return integer */ public function getDefaultBranchOnly() { @@ -214,7 +214,7 @@ class Project extends Model } /** - * @param $value int + * @param integer $value */ public function setId($value) { @@ -231,7 +231,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setTitle($value) { @@ -248,7 +248,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setReference($value) { @@ -265,7 +265,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setBranch($value) { @@ -282,7 +282,7 @@ class Project extends Model } /** - * @param $value int + * @param integer $value */ public function setDefaultBranchOnly($value) { @@ -299,7 +299,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setSshPrivateKey($value) { @@ -315,7 +315,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setType($value) { @@ -332,7 +332,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setLastCommit($value) { @@ -348,7 +348,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setBuildConfig($value) { @@ -364,7 +364,7 @@ class Project extends Model } /** - * @param $value string + * @param string $value */ public function setSshPublicKey($value) { @@ -380,7 +380,7 @@ class Project extends Model } /** - * @param $value int + * @param integer $value */ public function setAllowPublicStatus($value) { @@ -397,7 +397,7 @@ class Project extends Model } /** - * @param $value int + * @param integer $value */ public function setArchived($value) { @@ -414,7 +414,7 @@ class Project extends Model } /** - * @param $value int + * @param integer $value */ public function setGroupId($value) { @@ -437,52 +437,13 @@ class Project extends Model */ public function getGroup() { - $key = $this->getGroupId(); + $groupId = $this->getGroupId(); - if (empty($key)) { + if (empty($groupId)) { return null; } - $cacheKey = 'php-censor.project-group-' . $key; - $rtn = $this->cache->get($cacheKey); - - if (empty($rtn)) { - $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Group - Accepts an ID, an array representing a ProjectGroup or a ProjectGroup model. - * - * @param $value mixed - */ - public function setGroup($value) - { - // Is this an instance of ProjectGroup? - if ($value instanceof ProjectGroup) { - return $this->setGroupObject($value); - } - - // Is this an array representing a ProjectGroup item? - if (is_array($value) && !empty($value['id'])) { - return $this->setGroupId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setGroupId($value); - } - - /** - * Set Group - Accepts a ProjectGroup model. - * - * @param $value ProjectGroup - */ - public function setGroupObject(ProjectGroup $value) - { - return $this->setGroupId($value->getId()); + return Factory::getStore('ProjectGroup', 'PHPCensor')->getById($groupId); } /** @@ -613,17 +574,19 @@ class Project extends Model } /** - * @param $value \DateTime + * @param \DateTime $value */ - public function setCreateDate($value) + public function setCreateDate(\DateTime $value) { $this->validateDate('create_date', $value); - if ($this->data['create_date'] === $value) { + $stringValue = $value->format('Y-m-d H:i:s'); + + if ($this->data['create_date'] === $stringValue) { return; } - $this->data['create_date'] = $value; + $this->data['create_date'] = $stringValue; $this->setModified('create_date'); } @@ -639,7 +602,7 @@ class Project extends Model } /** - * @param $value integer + * @param integer $value */ public function setUserId($value) { @@ -726,22 +689,13 @@ class Project extends Model */ public function getEnvironmentsObjects() { - $key = $this->getId(); + $projectId = $this->getId(); - if (empty($key)) { + if (empty($projectId)) { return null; } - $cacheKey = 'php-censor.project-environments-' . $key; - $rtn = $this->cache->get($cacheKey); - - if (empty($rtn)) { - $store = $this->getEnvironmentStore(); - $rtn = $store->getByProjectId($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; + return $this->getEnvironmentStore()->getByProjectId($projectId); } /** diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 2847c8a6..4a05874f 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -43,7 +43,7 @@ class ProjectGroup extends Model ]; /** - * @return int + * @return integer */ public function getId() { @@ -53,7 +53,7 @@ class ProjectGroup extends Model } /** - * @param $value int + * @param integer $value */ public function setId($value) { @@ -80,7 +80,7 @@ class ProjectGroup extends Model } /** - * @param $value string + * @param string $value */ public function setTitle($value) { @@ -111,17 +111,19 @@ class ProjectGroup extends Model } /** - * @param $value \DateTime + * @param \DateTime $value */ - public function setCreateDate($value) + public function setCreateDate(\DateTime $value) { $this->validateDate('create_date', $value); - if ($this->data['create_date'] === $value) { + $stringValue = $value->format('Y-m-d H:i:s'); + + if ($this->data['create_date'] === $stringValue) { return; } - $this->data['create_date'] = $value; + $this->data['create_date'] = $stringValue; $this->setModified('create_date'); } @@ -137,7 +139,7 @@ class ProjectGroup extends Model } /** - * @param $value integer + * @param integer $value */ public function setUserId($value) { diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index dd1dceb6..405666be 100644 --- a/src/PHPCensor/Model/User.php +++ b/src/PHPCensor/Model/User.php @@ -64,7 +64,7 @@ class User extends Model ]; /** - * @return int + * @return integer */ public function getId() { @@ -104,7 +104,7 @@ class User extends Model } /** - * @return int + * @return integer */ public function getIsAdmin() { @@ -164,7 +164,7 @@ class User extends Model } /** - * @param $value int + * @param integer $value */ public function setId($value) { @@ -181,7 +181,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setEmail($value) { @@ -198,7 +198,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setHash($value) { @@ -215,7 +215,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setName($value) { @@ -232,7 +232,7 @@ class User extends Model } /** - * @param $value int + * @param integer $value */ public function setIsAdmin($value) { @@ -249,7 +249,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setProviderKey($value) { @@ -266,7 +266,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setProviderData($value) { @@ -282,7 +282,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setRememberKey($value) { @@ -298,7 +298,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setLanguage($value) { @@ -312,7 +312,7 @@ class User extends Model } /** - * @param $value string + * @param string $value */ public function setPerPage($value) { diff --git a/src/PHPCensor/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index 36ba2958..c583cec8 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -61,7 +61,7 @@ class BuildService ) { $build = new Build(); $build->setCreateDate(new \DateTime()); - $build->setProject($project); + $build->setProjectId($project->getId()); $build->setStatus(Build::STATUS_PENDING); $build->setEnvironment($environment); @@ -116,15 +116,17 @@ class BuildService { $data = $copyFrom->getDataArray(); - // Clean up unwanted properties from the original build: - unset($data['id']); - unset($data['status']); - unset($data['log']); - unset($data['start_date']); - unset($data['finish_date']); - $build = new Build(); - $build->setValues($data); + $build->setProjectId($data['project_id']); + $build->setCommitId($data['commit_id']); + $build->setBranch($data['branch']); + $build->setTag($data['tag']); + $build->setCommitterEmail($data['committer_email']); + $build->setCommitMessage($data['commit_message']); + $build->setExtra($data['extra']); + $build->setEnvironment($data['environment']); + $build->setSource($data['source']); + $build->setUserId($data['user_id']); $build->setCreateDate(new \DateTime()); $build->setStatus(Build::STATUS_PENDING); diff --git a/src/PHPCensor/Service/ProjectService.php b/src/PHPCensor/Service/ProjectService.php index 7822f062..b40fdbc4 100644 --- a/src/PHPCensor/Service/ProjectService.php +++ b/src/PHPCensor/Service/ProjectService.php @@ -96,7 +96,7 @@ class ProjectService } if (array_key_exists('group', $options)) { - $project->setGroup($options['group']); + $project->setGroupId($options['group']); } // Allow certain project types to set access information: diff --git a/src/PHPCensor/View/WidgetAllProjects/index-projects.phtml b/src/PHPCensor/View/WidgetAllProjects/index-projects.phtml index 1b046bac..e40264cc 100644 --- a/src/PHPCensor/View/WidgetAllProjects/index-projects.phtml +++ b/src/PHPCensor/View/WidgetAllProjects/index-projects.phtml @@ -88,7 +88,7 @@ foreach($projects as $project): ?>
- +

@@ -120,7 +120,7 @@ foreach($projects as $project): echo ''; } else { $build = $builds[$project->getId()][$idx]; - $link = APP_URL . 'build/view/' . $build->id; + $link = APP_URL . 'build/view/' . $build->getId(); switch ($build->getStatus()) { case 0: $class = 'bg-blue'; diff --git a/src/PHPCensor/View/WidgetAllProjects/update.phtml b/src/PHPCensor/View/WidgetAllProjects/update.phtml index 1f00e379..096796e8 100644 --- a/src/PHPCensor/View/WidgetAllProjects/update.phtml +++ b/src/PHPCensor/View/WidgetAllProjects/update.phtml @@ -87,7 +87,7 @@ if ($buildCount > 0) { ?>
- +

@@ -119,7 +119,7 @@ if ($buildCount > 0) { echo ''; } else { $build = $builds[$idx]; - $link = APP_URL . 'build/view/' . $build->id; + $link = APP_URL . 'build/view/' . $build->getId(); switch ($build->getStatus()) { case 0: $class = 'bg-blue'; diff --git a/src/PHPCensor/View/WidgetBuildErrors/update.phtml b/src/PHPCensor/View/WidgetBuildErrors/update.phtml index 47e46086..08b4a5eb 100644 --- a/src/PHPCensor/View/WidgetBuildErrors/update.phtml +++ b/src/PHPCensor/View/WidgetBuildErrors/update.phtml @@ -92,7 +92,7 @@ foreach($builds as $project_id => $project_envs): ?>
- +

@@ -127,7 +127,7 @@ foreach($builds as $project_id => $project_envs): echo ''; } else { $build = $project_env['latest'][$idx]; - $link = APP_URL . 'build/view/' . $build->id; + $link = APP_URL . 'build/view/' . $build->getId(); switch ($build->getStatus()) { case 0: $class = 'bg-blue'; diff --git a/tests/B8Framework/FormTest.php b/tests/B8Framework/FormTest.php index dcb58e41..e9def9d9 100755 --- a/tests/B8Framework/FormTest.php +++ b/tests/B8Framework/FormTest.php @@ -4,9 +4,8 @@ namespace Tests\b8; use b8\Form; use b8\Config; -use PHPUnit\Framework\TestCase; -class FormTest extends TestCase +class FormTest extends \PHPUnit\Framework\TestCase { public function testFormBasics() { @@ -17,7 +16,7 @@ class FormTest extends TestCase self::assertTrue($f->getAction() == '/'); self::assertTrue($f->getMethod() == 'POST'); - $config = new Config([ + new Config([ 'b8' => [ 'view' => [ 'path' => __DIR__ . '/data/view/' diff --git a/tests/PHPCensor/Helper/LangTest.php b/tests/PHPCensor/Helper/LangTest.php deleted file mode 100644 index a73687c1..00000000 --- a/tests/PHPCensor/Helper/LangTest.php +++ /dev/null @@ -1,43 +0,0 @@ - $enString) { - self::assertArrayHasKey($enIndex, $strings); - } - }*/ -} diff --git a/tests/PHPCensor/LocalizationTestCase.php b/tests/PHPCensor/LocalizationTestCase.php deleted file mode 100644 index d6ac7733..00000000 --- a/tests/PHPCensor/LocalizationTestCase.php +++ /dev/null @@ -1,24 +0,0 @@ -name, - $this->getName(false) - ); - - return $buffer . $this->getDataSetAsString(false); - } -} diff --git a/tests/PHPCensor/Model/BuildTest.php b/tests/PHPCensor/Model/BuildTest.php index 5f486af5..ccd76505 100644 --- a/tests/PHPCensor/Model/BuildTest.php +++ b/tests/PHPCensor/Model/BuildTest.php @@ -2,6 +2,7 @@ namespace Tests\PHPCensor\Model; +use b8\Exception\HttpException\ValidationException; use PHPCensor\Model\Build; use PHPCensor\Model; @@ -12,15 +13,67 @@ use PHPCensor\Model; */ class BuildTest extends \PHPUnit\Framework\TestCase { - public function setUp() - { - } - - public function testExecute_TestIsAValidModel() + public function testConstruct() { $build = new Build(); - self::assertTrue($build instanceof \b8\Model); - self::assertTrue($build instanceof Model); + + self::assertInstanceOf('PHPCensor\Model', $build); + self::assertInstanceOf('PHPCensor\Model\Build', $build); + + $build = new Build([ + 'project_id' => 100, + 'branch' => 'master', + ]); + + self::assertEquals([ + 'id' => null, + 'project_id' => 100, + 'commit_id' => null, + 'status' => null, + 'log' => null, + 'branch' => 'master', + 'tag' => null, + 'create_date' => null, + 'start_date' => null, + 'finish_date' => null, + 'committer_email' => null, + 'commit_message' => null, + 'extra' => null, + 'environment' => null, + 'source' => Build::SOURCE_UNKNOWN, + 'user_id' => 0, + ], $build->getDataArray()); + + try { + $build = new Build([ + 'project_id' => 101, + 'branch' => 'dev', + 'unknown' => 'unknown', + ]); + } catch (\InvalidArgumentException $e) { + self::assertEquals( + 'Model "PHPCensor\Model\Build" doesn\'t have field "unknown"', + $e->getMessage() + ); + } + + $build = new Build(); + $build->setLog('log'); + + self::assertEquals('log', $build->getLog()); + + $build->setLog(null); + + self::assertEquals(null, $build->getLog()); + + try { + $build->setLog([]); + } catch (ValidationException $e) { + self::assertEquals( + 'Column "log" must be a string.', + $e->getMessage() + ); + } } public function testExecute_TestBaseBuildDefaults() diff --git a/tests/PHPCensor/Model/ProjectTest.php b/tests/PHPCensor/Model/ProjectTest.php index a42ef82f..267c058c 100644 --- a/tests/PHPCensor/Model/ProjectTest.php +++ b/tests/PHPCensor/Model/ProjectTest.php @@ -15,7 +15,6 @@ class ProjectTest extends \PHPUnit\Framework\TestCase public function testExecute_TestIsAValidModel() { $project = new Project(); - self::assertTrue($project instanceof \b8\Model); self::assertTrue($project instanceof Model); } diff --git a/tests/PHPCensor/Service/BuildServiceTest.php b/tests/PHPCensor/Service/BuildServiceTest.php index ba0dd00d..b3f4d7dc 100644 --- a/tests/PHPCensor/Service/BuildServiceTest.php +++ b/tests/PHPCensor/Service/BuildServiceTest.php @@ -139,7 +139,7 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase { $build = new Build(); $build->setId(1); - $build->setProject(101); + $build->setProjectId(101); $build->setCommitId('abcde'); $build->setStatus(Build::STATUS_FAILED); $build->setLog('Test'); diff --git a/tests/PHPCensor/Service/BuiltStatusServiceTest.php b/tests/PHPCensor/Service/BuiltStatusServiceTest.php index 12ca714b..7b3cd438 100644 --- a/tests/PHPCensor/Service/BuiltStatusServiceTest.php +++ b/tests/PHPCensor/Service/BuiltStatusServiceTest.php @@ -94,7 +94,7 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase $project = $this->getProjectMock($config[$configId]['previousBuild'], $setProject); - $build->setProjectObject($project); + $build->setProjectId($project->getId()); return $build; } From 8b5a874789b72c6c3d9242d25c5e93a84f1f1840 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 14:30:34 +0700 Subject: [PATCH 04/28] Refactored Store. --- phpunit.xml | 28 +- src/B8Framework/Store.php | 251 ------------------ src/PHPCensor/Application.php | 11 +- src/PHPCensor/BuildFactory.php | 2 +- src/PHPCensor/Builder.php | 4 +- src/PHPCensor/Command/InstallCommand.php | 2 +- src/PHPCensor/Command/RebuildCommand.php | 4 +- src/PHPCensor/Command/RebuildQueueCommand.php | 2 +- src/PHPCensor/Command/RunCommand.php | 2 +- src/PHPCensor/Console/Application.php | 2 +- src/PHPCensor/Controller.php | 2 +- src/PHPCensor/Controller/BuildController.php | 12 +- .../Controller/BuildStatusController.php | 6 +- src/PHPCensor/Controller/GroupController.php | 7 +- .../Controller/ProjectController.php | 8 +- .../Controller/SessionController.php | 3 +- src/PHPCensor/Controller/UserController.php | 3 +- .../Controller/WebhookController.php | 9 +- .../WidgetAllProjectsController.php | 2 +- .../WidgetBuildErrorsController.php | 2 +- .../Controller/WidgetLastBuildsController.php | 2 +- src/PHPCensor/Helper/Lang.php | 3 +- src/PHPCensor/Logging/BuildDBLogHandler.php | 2 +- .../20151015124825_convert_errors.php | 2 +- ...23052715_added_request_branch_to_build.php | 2 +- src/PHPCensor/Model.php | 28 +- src/PHPCensor/Model/Build.php | 14 +- src/PHPCensor/Model/BuildError.php | 5 +- src/PHPCensor/Model/BuildMeta.php | 4 +- src/PHPCensor/Model/Project.php | 15 +- src/PHPCensor/Model/ProjectGroup.php | 6 +- src/PHPCensor/Plugin.php | 10 +- src/PHPCensor/Plugin/Util/Executor.php | 4 +- .../Authentication/UserProvider/Ldap.php | 2 +- src/PHPCensor/Store.php | 246 ++++++++++++++++- src/PHPCensor/Store/BuildErrorWriter.php | 1 - src/PHPCensor/Store/BuildStore.php | 1 - .../Store/Factory.php | 27 +- src/PHPCensor/View.php | 2 +- src/PHPCensor/Worker/BuildWorker.php | 2 +- tests/PHPCensor/Model/BuildTest.php | 23 +- tests/PHPCensor/Plugin/EmailTest.php | 32 ++- .../StoreMysqlTest.php | 14 +- .../StorePostgresqlTest.php | 12 +- 44 files changed, 397 insertions(+), 424 deletions(-) delete mode 100644 src/B8Framework/Store.php rename src/{B8Framework => PHPCensor}/Store/Factory.php (55%) rename tests/{B8Framework => PHPCensor}/StoreMysqlTest.php (95%) rename tests/{B8Framework => PHPCensor}/StorePostgresqlTest.php (96%) diff --git a/phpunit.xml b/phpunit.xml index bb92ca16..703620a2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -24,32 +24,8 @@ ./tests/B8Framework - - ./tests/PHPCensor/Helper - - - ./tests/PHPCensor/Controller - - - ./tests/PHPCensor/Logging - - - ./tests/PHPCensor/Model - - - ./tests/PHPCensor/Plugin - - - ./tests/PHPCensor/Service - - - ./tests/PHPCensor/Command - - - ./tests/PHPCensor/ProcessControl - - - ./tests/PHPCensor/Security + + ./tests/PHPCensor diff --git a/src/B8Framework/Store.php b/src/B8Framework/Store.php deleted file mode 100644 index 19e36977..00000000 --- a/src/B8Framework/Store.php +++ /dev/null @@ -1,251 +0,0 @@ -primaryKey)) { - throw new \RuntimeException('Save not implemented for this store.'); - } - } - - /** - * @param array $where - * @param integer $limit - * @param integer $offset - * @param array $order - * @param string $whereType - * - * @return array - */ - public function getWhere( - $where = [], - $limit = 25, - $offset = 0, - $order = [], - $whereType = 'AND' - ) { - $query = 'SELECT * FROM {{' . $this->tableName . '}}'; - $countQuery = 'SELECT COUNT(*) AS {{count}} FROM {{' . $this->tableName . '}}'; - - $wheres = []; - $params = []; - foreach ($where as $key => $value) { - $key = $this->fieldCheck($key); - - if (!is_array($value)) { - $params[] = $value; - $wheres[] = $key . ' = ?'; - } - } - - if (count($wheres)) { - $query .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; - $countQuery .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; - } - - if (count($order)) { - $orders = []; - foreach ($order as $key => $value) { - $orders[] = $this->fieldCheck($key) . ' ' . $value; - } - - $query .= ' ORDER BY ' . implode(', ', $orders); - } - - if ($limit) { - $query .= ' LIMIT ' . $limit; - } - - if ($offset) { - $query .= ' OFFSET ' . $offset; - } - - $stmt = Database::getConnection('read')->prepareCommon($countQuery); - $stmt->execute($params); - $res = $stmt->fetch(\PDO::FETCH_ASSOC); - $count = (int)$res['count']; - - $stmt = Database::getConnection('read')->prepareCommon($query); - $stmt->execute($params); - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - $rtn = []; - - foreach ($res as $data) { - $rtn[] = new $this->modelName($data); - } - - return ['items' => $rtn, 'count' => $count]; - } - - /** - * @param Model $obj - * @param boolean $saveAllColumns - * - * @throws \RuntimeException - * @throws \InvalidArgumentException - * - * @return Model|null - */ - public function save(Model $obj, $saveAllColumns = false) - { - if (!($obj instanceof $this->modelName)) { - throw new \InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.'); - } - - $data = $obj->getDataArray(); - - if (isset($data[$this->primaryKey])) { - $rtn = $this->saveByUpdate($obj, $saveAllColumns); - } else { - $rtn = $this->saveByInsert($obj, $saveAllColumns); - } - - return $rtn; - } - - /** - * @param Model $obj - * @param bool $saveAllColumns - * - * @return Model|null - */ - public function saveByUpdate(Model $obj, $saveAllColumns = false) - { - $rtn = null; - $data = $obj->getDataArray(); - $modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified(); - - $updates = []; - $update_params = []; - foreach ($modified as $key) { - $updates[] = $key . ' = :' . $key; - $update_params[] = [$key, $data[$key]]; - } - - if (count($updates)) { - $qs = 'UPDATE {{' . $this->tableName . '}} SET ' . implode(', ', $updates) . ' WHERE {{' . $this->primaryKey . '}} = :primaryKey'; - $q = Database::getConnection('write')->prepareCommon($qs); - - foreach ($update_params as $update_param) { - $q->bindValue(':' . $update_param[0], $update_param[1]); - } - - $q->bindValue(':primaryKey', $data[$this->primaryKey]); - $q->execute(); - - $rtn = $this->getByPrimaryKey($data[$this->primaryKey], 'write'); - } else { - $rtn = $obj; - } - - return $rtn; - } - - /** - * @param Model $obj - * @param bool $saveAllColumns - * - * @return Model|null - */ - public function saveByInsert(Model $obj, $saveAllColumns = false) - { - $rtn = null; - $data = $obj->getDataArray(); - $modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified(); - - $cols = []; - $values = []; - $qParams = []; - foreach ($modified as $key) { - $cols[] = $key; - $values[] = ':' . $key; - $qParams[':' . $key] = $data[$key]; - } - - if (count($cols)) { - $qs = 'INSERT INTO {{' . $this->tableName . '}} (' . implode(', ', $cols) . ') VALUES (' . implode(', ', $values) . ')'; - $q = Database::getConnection('write')->prepareCommon($qs); - - if ($q->execute($qParams)) { - $id = Database::getConnection('write')->lastInsertIdExtended($obj->getTableName()); - $rtn = $this->getByPrimaryKey($id, 'write'); - } - } - - return $rtn; - } - - /** - * @param Model $obj - * - * @throws \RuntimeException - * @throws \InvalidArgumentException - * - * @return boolean - */ - public function delete(Model $obj) - { - if (!($obj instanceof $this->modelName)) { - throw new \InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.'); - } - - $data = $obj->getDataArray(); - - $q = Database::getConnection('write')->prepareCommon('DELETE FROM {{' . $this->tableName . '}} WHERE {{' . $this->primaryKey . '}} = :primaryKey'); - $q->bindValue(':primaryKey', $data[$this->primaryKey]); - $q->execute(); - - return true; - } - - /** - * @param string $field - * - * @throws \InvalidArgumentException - * - * @return string - */ - protected function fieldCheck($field) - { - if (empty($field)) { - throw new \InvalidArgumentException('You cannot have an empty field name.'); - } - - if (strpos($field, '.') === false) { - return '{{' . $this->tableName . '}}.{{' . $field . '}}'; - } - - return $field; - } -} diff --git a/src/PHPCensor/Application.php b/src/PHPCensor/Application.php index 514626a6..d2a1f141 100644 --- a/src/PHPCensor/Application.php +++ b/src/PHPCensor/Application.php @@ -6,6 +6,7 @@ use b8; use b8\Exception\HttpException; use b8\Http\Response; use b8\Http\Response\RedirectResponse; +use PHPCensor\Store\Factory; /** * @author Dan Cryer @@ -29,7 +30,7 @@ class Application extends b8\Application // Inlined as a closure to fix "using $this when not in object context" on 5.3 $validateSession = function () { if (!empty($_SESSION['php-censor-user-id'])) { - $user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['php-censor-user-id']); + $user = Factory::getStore('User')->getByPrimaryKey($_SESSION['php-censor-user-id']); if ($user) { return true; @@ -128,17 +129,17 @@ class Application extends b8\Application protected function setLayoutVariables(View &$layout) { $groups = []; - $groupStore = b8\Store\Factory::getStore('ProjectGroup'); + $groupStore = Factory::getStore('ProjectGroup'); $groupList = $groupStore->getWhere([], 100, 0, ['title' => 'ASC']); foreach ($groupList['items'] as $group) { $thisGroup = ['title' => $group->getTitle()]; - $projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId(), false); + $projects = Factory::getStore('Project')->getByGroupId($group->getId(), false); $thisGroup['projects'] = $projects['items']; $groups[] = $thisGroup; } - $archived_projects = b8\Store\Factory::getStore('Project')->getAll(true); + $archived_projects = Factory::getStore('Project')->getAll(true); $layout->archived_projects = $archived_projects['items']; $layout->groups = $groups; } @@ -155,7 +156,7 @@ class Application extends b8\Application $defaultUserId = (integer)$config->get('php-censor.security.default_user_id', 1); if ($disableAuth && $defaultUserId) { - $user = b8\Store\Factory::getStore('User')->getByPrimaryKey($defaultUserId); + $user = Factory::getStore('User')->getByPrimaryKey($defaultUserId); if ($user) { return true; diff --git a/src/PHPCensor/BuildFactory.php b/src/PHPCensor/BuildFactory.php index 7ed532d4..f217b295 100644 --- a/src/PHPCensor/BuildFactory.php +++ b/src/PHPCensor/BuildFactory.php @@ -2,7 +2,7 @@ namespace PHPCensor; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Model\Build; /** diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 896c2e59..a0df4ae9 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -6,8 +6,8 @@ use PHPCensor\Helper\BuildInterpolator; use PHPCensor\Helper\MailerFactory; use PHPCensor\Logging\BuildLogger; use PHPCensor\Model\Build; +use PHPCensor\Store\Factory; use b8\Config; -use b8\Store\Factory; use PHPCensor\Store\BuildErrorWriter; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; @@ -103,7 +103,7 @@ class Builder implements LoggerAwareInterface public function __construct(Build $build, LoggerInterface $logger = null) { $this->build = $build; - $this->store = Factory::getStore('Build', 'PHPCensor'); + $this->store = Factory::getStore('Build'); $this->buildLogger = new BuildLogger($logger, $build); $pluginFactory = $this->buildPluginFactory($build); diff --git a/src/PHPCensor/Command/InstallCommand.php b/src/PHPCensor/Command/InstallCommand.php index 285749d3..993d0437 100644 --- a/src/PHPCensor/Command/InstallCommand.php +++ b/src/PHPCensor/Command/InstallCommand.php @@ -6,7 +6,7 @@ use Exception; use PDO; use b8\Config; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Model\ProjectGroup; use PHPCensor\Store\UserStore; use PHPCensor\Store\ProjectGroupStore; diff --git a/src/PHPCensor/Command/RebuildCommand.php b/src/PHPCensor/Command/RebuildCommand.php index e62dcab0..f1e4da40 100644 --- a/src/PHPCensor/Command/RebuildCommand.php +++ b/src/PHPCensor/Command/RebuildCommand.php @@ -2,7 +2,7 @@ namespace PHPCensor\Command; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use Monolog\Logger; use PHPCensor\Service\BuildService; use Symfony\Component\Console\Command\Command; @@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** * Re-runs the last run build. - * + * * @author Dan Cryer */ class RebuildCommand extends Command diff --git a/src/PHPCensor/Command/RebuildQueueCommand.php b/src/PHPCensor/Command/RebuildQueueCommand.php index 47837021..e43f6720 100644 --- a/src/PHPCensor/Command/RebuildQueueCommand.php +++ b/src/PHPCensor/Command/RebuildQueueCommand.php @@ -2,7 +2,7 @@ namespace PHPCensor\Command; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use Monolog\Logger; use PHPCensor\BuildFactory; use PHPCensor\Logging\OutputLogHandler; diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 0f6c582a..81885b4a 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -11,7 +11,7 @@ use PHPCensor\Store\BuildStore; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Builder; use PHPCensor\BuildFactory; use PHPCensor\Model\Build; diff --git a/src/PHPCensor/Console/Application.php b/src/PHPCensor/Console/Application.php index f599913e..a6f3152d 100644 --- a/src/PHPCensor/Console/Application.php +++ b/src/PHPCensor/Console/Application.php @@ -3,7 +3,7 @@ namespace PHPCensor\Console; use b8\Config; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\StreamHandler; use Monolog\Logger; diff --git a/src/PHPCensor/Controller.php b/src/PHPCensor/Controller.php index 02276580..4de9203f 100644 --- a/src/PHPCensor/Controller.php +++ b/src/PHPCensor/Controller.php @@ -6,7 +6,7 @@ use b8\Config; use b8\Exception\HttpException\ForbiddenException; use b8\Http\Request; use b8\Http\Response; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Model\User; use PHPCensor\Store\UserStore; diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index 8de3cb43..28b97d07 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -10,11 +10,11 @@ use PHPCensor\BuildFactory; use PHPCensor\Helper\AnsiConverter; use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; -use PHPCensor\Model\Project; use PHPCensor\Model\User; use PHPCensor\Service\BuildService; use PHPCensor\Controller; use PHPCensor\View; +use PHPCensor\Store\Factory; /** * Build Controller - Allows users to run and view builds. @@ -38,7 +38,7 @@ class BuildController extends Controller */ public function init() { - $this->buildStore = b8\Store\Factory::getStore('Build'); + $this->buildStore = Factory::getStore('Build'); $this->buildService = new BuildService($this->buildStore); } @@ -81,7 +81,7 @@ class BuildController extends Controller } /** @var \PHPCensor\Store\BuildErrorStore $errorStore */ - $errorStore = b8\Store\Factory::getStore('BuildError'); + $errorStore = Factory::getStore('BuildError'); $this->view->uiPlugins = $this->getUiPlugins(); $this->view->build = $build; @@ -125,7 +125,7 @@ class BuildController extends Controller $delete = Lang::get('delete_build'); $deleteLink = APP_URL . 'build/delete/' . $build->getId(); - $project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($build->getProjectId()); + $project = Factory::getStore('Project')->getByPrimaryKey($build->getProjectId()); $actions = ''; if (!$project->getArchived()) { @@ -183,7 +183,7 @@ class BuildController extends Controller $data['duration'] = $build->getDuration(); /** @var \PHPCensor\Store\BuildErrorStore $errorStore */ - $errorStore = b8\Store\Factory::getStore('BuildError'); + $errorStore = Factory::getStore('BuildError'); $errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity, $isNew); $errorView = new View('Build/errors'); @@ -240,7 +240,7 @@ class BuildController extends Controller public function rebuild($buildId) { $copy = BuildFactory::getBuildById($buildId); - $project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($copy->getProjectId()); + $project = Factory::getStore('Project')->getByPrimaryKey($copy->getProjectId()); if (!$copy || $project->getArchived()) { throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); diff --git a/src/PHPCensor/Controller/BuildStatusController.php b/src/PHPCensor/Controller/BuildStatusController.php index 3124e83c..a8d42004 100644 --- a/src/PHPCensor/Controller/BuildStatusController.php +++ b/src/PHPCensor/Controller/BuildStatusController.php @@ -4,7 +4,7 @@ namespace PHPCensor\Controller; use b8; use b8\Exception\HttpException\NotFoundException; -use b8\Store; +use PHPCensor\Store\Factory; use PHPCensor\BuildFactory; use PHPCensor\Model\Project; use PHPCensor\Model\Build; @@ -31,8 +31,8 @@ class BuildStatusController extends Controller { $this->response->disableLayout(); - $this->buildStore = Store\Factory::getStore('Build'); - $this->projectStore = Store\Factory::getStore('Project'); + $this->buildStore = Factory::getStore('Build'); + $this->projectStore = Factory::getStore('Project'); } /** diff --git a/src/PHPCensor/Controller/GroupController.php b/src/PHPCensor/Controller/GroupController.php index 7be5830b..5cb04c76 100644 --- a/src/PHPCensor/Controller/GroupController.php +++ b/src/PHPCensor/Controller/GroupController.php @@ -8,6 +8,7 @@ use PHPCensor\Controller; use PHPCensor\Model\ProjectGroup; use PHPCensor\Helper\Lang; use PHPCensor\Model\User; +use PHPCensor\Store\Factory; /** * Project Controller - Allows users to create, edit and view projects. @@ -26,7 +27,7 @@ class GroupController extends Controller */ public function init() { - $this->groupStore = b8\Store\Factory::getStore('ProjectGroup'); + $this->groupStore = Factory::getStore('ProjectGroup'); } /** @@ -44,8 +45,8 @@ class GroupController extends Controller 'title' => $group->getTitle(), 'id' => $group->getId(), ]; - $projects_active = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId(), false); - $projects_archived = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId(), true); + $projects_active = Factory::getStore('Project')->getByGroupId($group->getId(), false); + $projects_archived = Factory::getStore('Project')->getByGroupId($group->getId(), true); $thisGroup['projects'] = array_merge($projects_active['items'], $projects_archived['items']); $groups[] = $thisGroup; diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index a639311e..c222c43f 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -5,7 +5,6 @@ namespace PHPCensor\Controller; use b8; use b8\Exception\HttpException\NotFoundException; use b8\Form; -use b8\Store; use JasonGrimes\Paginator; use PHPCensor; use PHPCensor\BuildFactory; @@ -17,6 +16,7 @@ use PHPCensor\Service\ProjectService; use PHPCensor\Model\Build; use b8\Http\Response\RedirectResponse; use PHPCensor\View; +use PHPCensor\Store\Factory; /** * Project Controller - Allows users to create, edit and view projects. @@ -50,8 +50,8 @@ class ProjectController extends PHPCensor\Controller */ public function init() { - $this->buildStore = Store\Factory::getStore('Build'); - $this->projectStore = Store\Factory::getStore('Project'); + $this->buildStore = Factory::getStore('Build'); + $this->projectStore = Factory::getStore('Project'); $this->projectService = new ProjectService($this->projectStore); $this->buildService = new BuildService($this->buildStore); } @@ -495,7 +495,7 @@ class ProjectController extends PHPCensor\Controller $field->setClass('form-control')->setContainerClass('form-group')->setValue(1); $groups = []; - $groupStore = b8\Store\Factory::getStore('ProjectGroup'); + $groupStore = Factory::getStore('ProjectGroup'); $groupList = $groupStore->getWhere([], 100, 0, ['title' => 'ASC']); foreach ($groupList['items'] as $group) { diff --git a/src/PHPCensor/Controller/SessionController.php b/src/PHPCensor/Controller/SessionController.php index 122ad509..d61d357e 100644 --- a/src/PHPCensor/Controller/SessionController.php +++ b/src/PHPCensor/Controller/SessionController.php @@ -8,6 +8,7 @@ use PHPCensor\Helper\Lang; use PHPCensor\Controller; use PHPCensor\Security\Authentication\Service; use PHPCensor\Store\UserStore; +use PHPCensor\Store\Factory; /** * Session Controller - Handles user login / logout. @@ -33,7 +34,7 @@ class SessionController extends Controller { $this->response->disableLayout(); - $this->userStore = b8\Store\Factory::getStore('User'); + $this->userStore = Factory::getStore('User'); $this->authentication = Service::getInstance(); } diff --git a/src/PHPCensor/Controller/UserController.php b/src/PHPCensor/Controller/UserController.php index 42e340b2..1ad35a69 100644 --- a/src/PHPCensor/Controller/UserController.php +++ b/src/PHPCensor/Controller/UserController.php @@ -10,6 +10,7 @@ use PHPCensor\Helper\Lang; use PHPCensor\Model\User; use PHPCensor\Service\UserService; use PHPCensor\View; +use PHPCensor\Store\Factory; /** * User Controller - Allows an administrator to view, add, edit and delete users. @@ -33,7 +34,7 @@ class UserController extends Controller */ public function init() { - $this->userStore = b8\Store\Factory::getStore('User'); + $this->userStore = Factory::getStore('User'); $this->userService = new UserService($this->userStore); } diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 58bdd0c1..49a25266 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -3,7 +3,6 @@ namespace PHPCensor\Controller; use b8; -use b8\Store; use Exception; use GuzzleHttp\Client; use PHPCensor\Helper\Lang; @@ -15,7 +14,7 @@ use PHPCensor\Store\ProjectStore; use b8\Controller; use b8\Config; use b8\Exception\HttpException\NotFoundException; -use b8\Store\Factory; +use PHPCensor\Store\Factory; /** * Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc. @@ -48,8 +47,8 @@ class WebhookController extends Controller */ public function init() { - $this->buildStore = Store\Factory::getStore('Build'); - $this->projectStore = Store\Factory::getStore('Project'); + $this->buildStore = Factory::getStore('Build'); + $this->projectStore = Factory::getStore('Project'); $this->buildService = new BuildService($this->buildStore); } @@ -674,7 +673,7 @@ class WebhookController extends Controller $envsUpdated = []; $envObjects = $project->getEnvironmentsObjects(); - $store = Factory::getStore('Environment', 'PHPCensor'); + $store = Factory::getStore('Environment'); foreach ($envObjects['items'] as $environment) { $branches = $environment->getBranches(); if (in_array($environment->getName(), $envs)) { diff --git a/src/PHPCensor/Controller/WidgetAllProjectsController.php b/src/PHPCensor/Controller/WidgetAllProjectsController.php index b6bc5f53..4b1fb50b 100644 --- a/src/PHPCensor/Controller/WidgetAllProjectsController.php +++ b/src/PHPCensor/Controller/WidgetAllProjectsController.php @@ -4,7 +4,7 @@ namespace PHPCensor\Controller; use PHPCensor\Model\Build; use PHPCensor\Controller; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\View; use PHPCensor\Model\Project; use b8\Http\Response; diff --git a/src/PHPCensor/Controller/WidgetBuildErrorsController.php b/src/PHPCensor/Controller/WidgetBuildErrorsController.php index b0e1e73a..c80c2656 100644 --- a/src/PHPCensor/Controller/WidgetBuildErrorsController.php +++ b/src/PHPCensor/Controller/WidgetBuildErrorsController.php @@ -2,7 +2,7 @@ namespace PHPCensor\Controller; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\View; use b8\Http\Response; use PHPCensor\Controller; diff --git a/src/PHPCensor/Controller/WidgetLastBuildsController.php b/src/PHPCensor/Controller/WidgetLastBuildsController.php index a613a25f..cb3ecd84 100644 --- a/src/PHPCensor/Controller/WidgetLastBuildsController.php +++ b/src/PHPCensor/Controller/WidgetLastBuildsController.php @@ -2,7 +2,7 @@ namespace PHPCensor\Controller; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\View; use b8\Http\Response; use PHPCensor\BuildFactory; diff --git a/src/PHPCensor/Helper/Lang.php b/src/PHPCensor/Helper/Lang.php index 0e340a02..5322ecda 100644 --- a/src/PHPCensor/Helper/Lang.php +++ b/src/PHPCensor/Helper/Lang.php @@ -3,8 +3,7 @@ namespace PHPCensor\Helper; use b8\Config; -use b8\Store\Factory; -use PHPCensor\Model\User; +use PHPCensor\Store\Factory; use PHPCensor\Store\UserStore; /** diff --git a/src/PHPCensor/Logging/BuildDBLogHandler.php b/src/PHPCensor/Logging/BuildDBLogHandler.php index 942b358e..80edadd0 100644 --- a/src/PHPCensor/Logging/BuildDBLogHandler.php +++ b/src/PHPCensor/Logging/BuildDBLogHandler.php @@ -2,7 +2,7 @@ namespace PHPCensor\Logging; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use Monolog\Handler\AbstractProcessingHandler; use PHPCensor\Model\Build; use Psr\Log\LogLevel; diff --git a/src/PHPCensor/Migrations/20151015124825_convert_errors.php b/src/PHPCensor/Migrations/20151015124825_convert_errors.php index 40efd1a3..1c4d0d05 100644 --- a/src/PHPCensor/Migrations/20151015124825_convert_errors.php +++ b/src/PHPCensor/Migrations/20151015124825_convert_errors.php @@ -3,7 +3,7 @@ use Phinx\Migration\AbstractMigration; use PHPCensor\Model\BuildMeta; use PHPCensor\Model\BuildError; -use b8\Store\Factory; +use PHPCensor\Store\Factory; class ConvertErrors extends AbstractMigration { diff --git a/src/PHPCensor/Migrations/20180223052715_added_request_branch_to_build.php b/src/PHPCensor/Migrations/20180223052715_added_request_branch_to_build.php index edf1bdde..d2390c54 100644 --- a/src/PHPCensor/Migrations/20180223052715_added_request_branch_to_build.php +++ b/src/PHPCensor/Migrations/20180223052715_added_request_branch_to_build.php @@ -1,7 +1,7 @@ @@ -306,8 +306,6 @@ class Build extends Model */ public function setCreateDate(\DateTime $value) { - $this->validateDate('create_date', $value); - $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { @@ -338,8 +336,6 @@ class Build extends Model */ public function setStartDate(\DateTime $value) { - $this->validateDate('start_date', $value); - $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['start_date'] === $stringValue) { @@ -370,8 +366,6 @@ class Build extends Model */ public function setFinishDate(\DateTime $value) { - $this->validateDate('finish_date', $value); - $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['finish_date'] === $stringValue) { @@ -644,7 +638,7 @@ class Build extends Model return null; } - return Factory::getStore('Project', 'PHPCensor')->getById($key); + return Factory::getStore('Project')->getById($key); } /** @@ -654,7 +648,7 @@ class Build extends Model */ public function getBuildBuildErrors() { - return Factory::getStore('BuildError', 'PHPCensor')->getByBuildId($this->getId()); + return Factory::getStore('BuildError')->getByBuildId($this->getId()); } /** @@ -664,7 +658,7 @@ class Build extends Model */ public function getBuildBuildMetas() { - return Factory::getStore('BuildMeta', 'PHPCensor')->getByBuildId($this->getId()); + return Factory::getStore('BuildMeta')->getByBuildId($this->getId()); } /** diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index ba9ff575..a4492b79 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -3,7 +3,7 @@ namespace PHPCensor\Model; use PHPCensor\Model; -use b8\Store\Factory; +use PHPCensor\Store\Factory; class BuildError extends Model { @@ -326,7 +326,6 @@ class BuildError extends Model public function setCreateDate(\DateTime $value) { $this->validateNotNull('create_date', $value); - $this->validateDate('create_date', $value); $stringValue = $value->format('Y-m-d H:i:s'); @@ -385,7 +384,7 @@ class BuildError extends Model return null; } - return Factory::getStore('Build', 'PHPCensor')->getById($buildId); + return Factory::getStore('Build')->getById($buildId); } /** diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 0ec7fdb5..68c2fb79 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -3,7 +3,7 @@ namespace PHPCensor\Model; use PHPCensor\Model; -use b8\Store\Factory; +use PHPCensor\Store\Factory; class BuildMeta extends Model { @@ -167,6 +167,6 @@ class BuildMeta extends Model return null; } - return Factory::getStore('Build', 'PHPCensor')->getById($buildId); + return Factory::getStore('Build')->getById($buildId); } } diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 688838b6..56e6ec9d 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -3,8 +3,7 @@ namespace PHPCensor\Model; use PHPCensor\Model; -use b8\Store; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Store\EnvironmentStore; use Symfony\Component\Yaml\Parser as YamlParser; use Symfony\Component\Yaml\Dumper as YamlDumper; @@ -443,7 +442,7 @@ class Project extends Model return null; } - return Factory::getStore('ProjectGroup', 'PHPCensor')->getById($groupId); + return Factory::getStore('ProjectGroup')->getById($groupId); } /** @@ -453,7 +452,7 @@ class Project extends Model */ public function getProjectBuilds() { - return Factory::getStore('Build', 'PHPCensor')->getByProjectId($this->getId()); + return Factory::getStore('Build')->getByProjectId($this->getId()); } /** @@ -473,7 +472,7 @@ class Project extends Model } $order = ['id' => 'DESC']; - $builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 0, $order); + $builds = Factory::getStore('Build')->getWhere($criteria, 1, 0, $order); if (is_array($builds['items']) && count($builds['items'])) { $latest = array_shift($builds['items']); @@ -497,7 +496,7 @@ class Project extends Model { $criteria = ['branch' => $branch, 'project_id' => $this->getId()]; $order = ['id' => 'DESC']; - $builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 1, $order); + $builds = Factory::getStore('Build')->getWhere($criteria, 1, 1, $order); if (is_array($builds['items']) && count($builds['items'])) { $previous = array_shift($builds['items']); @@ -578,8 +577,6 @@ class Project extends Model */ public function setCreateDate(\DateTime $value) { - $this->validateDate('create_date', $value); - $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { @@ -678,7 +675,7 @@ class Project extends Model protected function getEnvironmentStore() { /** @var EnvironmentStore $store */ - $store = Factory::getStore('Environment', 'PHPCensor'); + $store = Factory::getStore('Environment'); return $store; } diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 4a05874f..5e9d75dc 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -3,7 +3,7 @@ namespace PHPCensor\Model; use PHPCensor\Model; -use b8\Store\Factory; +use PHPCensor\Store\Factory; class ProjectGroup extends Model { @@ -115,8 +115,6 @@ class ProjectGroup extends Model */ public function setCreateDate(\DateTime $value) { - $this->validateDate('create_date', $value); - $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { @@ -162,6 +160,6 @@ class ProjectGroup extends Model */ public function getGroupProjects() { - return Factory::getStore('Project', 'PHPCensor')->getByGroupId($this->getId(), false); + return Factory::getStore('Project')->getByGroupId($this->getId(), false); } } diff --git a/src/PHPCensor/Plugin.php b/src/PHPCensor/Plugin.php index 0a382dcb..cfc4658e 100644 --- a/src/PHPCensor/Plugin.php +++ b/src/PHPCensor/Plugin.php @@ -45,7 +45,7 @@ abstract class Plugin $this->build = $build; $this->options = $options; - if (!empty($options['priority_path']) && in_array($options['priority_path'], ['global', 'system'])) { + if (!empty($options['priority_path']) && in_array($options['priority_path'], ['global', 'system'], true)) { $this->priorityPath = $options['priority_path']; } @@ -83,6 +83,14 @@ abstract class Plugin return $this->builder; } + /** + * @return string + */ + public function getPriorityPath() + { + return $this->priorityPath; + } + /** * @return boolean */ diff --git a/src/PHPCensor/Plugin/Util/Executor.php b/src/PHPCensor/Plugin/Util/Executor.php index c36bf7f3..0bf44079 100644 --- a/src/PHPCensor/Plugin/Util/Executor.php +++ b/src/PHPCensor/Plugin/Util/Executor.php @@ -2,7 +2,7 @@ namespace PHPCensor\Plugin\Util; -use b8\Store\Factory as StoreFactory; +use PHPCensor\Store\Factory as StoreFactory; use Exception; use PHPCensor\Helper\Lang; use PHPCensor\Logging\BuildLogger; @@ -162,7 +162,7 @@ class Executor $success = true; foreach ($plugins as $plugin => $options) { - $this->logger->log("\n" . + $this->logger->log("\n" . sprintf('RUNNING PLUGIN: %s', Lang::get($plugin)) . ' (' . 'Stage' . ': ' . ucfirst($stage) . ')' ); diff --git a/src/PHPCensor/Security/Authentication/UserProvider/Ldap.php b/src/PHPCensor/Security/Authentication/UserProvider/Ldap.php index 6fa3470e..54163f63 100644 --- a/src/PHPCensor/Security/Authentication/UserProvider/Ldap.php +++ b/src/PHPCensor/Security/Authentication/UserProvider/Ldap.php @@ -2,7 +2,7 @@ namespace PHPCensor\Security\Authentication\UserProvider; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Model\User; use PHPCensor\Security\Authentication\LoginPasswordProviderInterface; use PHPCensor\Service\UserService; diff --git a/src/PHPCensor/Store.php b/src/PHPCensor/Store.php index 5a9ce1d6..b4dd9abd 100644 --- a/src/PHPCensor/Store.php +++ b/src/PHPCensor/Store.php @@ -2,6 +2,250 @@ namespace PHPCensor; -abstract class Store extends \b8\Store +use b8\Database; + +abstract class Store { + /** + * @var string + */ + protected $modelName = null; + + /** + * @var string + */ + protected $tableName = null; + + /** + * @var string + */ + protected $primaryKey = null; + + /** + * @param string $key + * @param string $useConnection + * + * @return Model|null + */ + abstract public function getByPrimaryKey($key, $useConnection = 'read'); + + /** + * @throws \RuntimeException + */ + public function __construct() + { + if (empty($this->primaryKey)) { + throw new \RuntimeException('Save not implemented for this store.'); + } + } + + /** + * @param array $where + * @param integer $limit + * @param integer $offset + * @param array $order + * @param string $whereType + * + * @return array + */ + public function getWhere( + $where = [], + $limit = 25, + $offset = 0, + $order = [], + $whereType = 'AND' + ) { + $query = 'SELECT * FROM {{' . $this->tableName . '}}'; + $countQuery = 'SELECT COUNT(*) AS {{count}} FROM {{' . $this->tableName . '}}'; + + $wheres = []; + $params = []; + foreach ($where as $key => $value) { + $key = $this->fieldCheck($key); + + if (!is_array($value)) { + $params[] = $value; + $wheres[] = $key . ' = ?'; + } + } + + if (count($wheres)) { + $query .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; + $countQuery .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; + } + + if (count($order)) { + $orders = []; + foreach ($order as $key => $value) { + $orders[] = $this->fieldCheck($key) . ' ' . $value; + } + + $query .= ' ORDER BY ' . implode(', ', $orders); + } + + if ($limit) { + $query .= ' LIMIT ' . $limit; + } + + if ($offset) { + $query .= ' OFFSET ' . $offset; + } + + $stmt = Database::getConnection('read')->prepareCommon($countQuery); + $stmt->execute($params); + $res = $stmt->fetch(\PDO::FETCH_ASSOC); + $count = (int)$res['count']; + + $stmt = Database::getConnection('read')->prepareCommon($query); + $stmt->execute($params); + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $rtn = []; + + foreach ($res as $data) { + $rtn[] = new $this->modelName($data); + } + + return ['items' => $rtn, 'count' => $count]; + } + + /** + * @param Model $obj + * @param boolean $saveAllColumns + * + * @throws \RuntimeException + * @throws \InvalidArgumentException + * + * @return Model|null + */ + public function save(Model $obj, $saveAllColumns = false) + { + if (!($obj instanceof $this->modelName)) { + throw new \InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.'); + } + + $data = $obj->getDataArray(); + + if (isset($data[$this->primaryKey])) { + $rtn = $this->saveByUpdate($obj, $saveAllColumns); + } else { + $rtn = $this->saveByInsert($obj, $saveAllColumns); + } + + return $rtn; + } + + /** + * @param Model $obj + * @param bool $saveAllColumns + * + * @return Model|null + */ + public function saveByUpdate(Model $obj, $saveAllColumns = false) + { + $rtn = null; + $data = $obj->getDataArray(); + $modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified(); + + $updates = []; + $update_params = []; + foreach ($modified as $key) { + $updates[] = $key . ' = :' . $key; + $update_params[] = [$key, $data[$key]]; + } + + if (count($updates)) { + $qs = 'UPDATE {{' . $this->tableName . '}} SET ' . implode(', ', $updates) . ' WHERE {{' . $this->primaryKey . '}} = :primaryKey'; + $q = Database::getConnection('write')->prepareCommon($qs); + + foreach ($update_params as $update_param) { + $q->bindValue(':' . $update_param[0], $update_param[1]); + } + + $q->bindValue(':primaryKey', $data[$this->primaryKey]); + $q->execute(); + + $rtn = $this->getByPrimaryKey($data[$this->primaryKey], 'write'); + } else { + $rtn = $obj; + } + + return $rtn; + } + + /** + * @param Model $obj + * @param bool $saveAllColumns + * + * @return Model|null + */ + public function saveByInsert(Model $obj, $saveAllColumns = false) + { + $rtn = null; + $data = $obj->getDataArray(); + $modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified(); + + $cols = []; + $values = []; + $qParams = []; + foreach ($modified as $key) { + $cols[] = $key; + $values[] = ':' . $key; + $qParams[':' . $key] = $data[$key]; + } + + if (count($cols)) { + $qs = 'INSERT INTO {{' . $this->tableName . '}} (' . implode(', ', $cols) . ') VALUES (' . implode(', ', $values) . ')'; + $q = Database::getConnection('write')->prepareCommon($qs); + + if ($q->execute($qParams)) { + $id = Database::getConnection('write')->lastInsertIdExtended($obj->getTableName()); + $rtn = $this->getByPrimaryKey($id, 'write'); + } + } + + return $rtn; + } + + /** + * @param Model $obj + * + * @throws \RuntimeException + * @throws \InvalidArgumentException + * + * @return boolean + */ + public function delete(Model $obj) + { + if (!($obj instanceof $this->modelName)) { + throw new \InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.'); + } + + $data = $obj->getDataArray(); + + $q = Database::getConnection('write')->prepareCommon('DELETE FROM {{' . $this->tableName . '}} WHERE {{' . $this->primaryKey . '}} = :primaryKey'); + $q->bindValue(':primaryKey', $data[$this->primaryKey]); + $q->execute(); + + return true; + } + + /** + * @param string $field + * + * @throws \InvalidArgumentException + * + * @return string + */ + protected function fieldCheck($field) + { + if (empty($field)) { + throw new \InvalidArgumentException('You cannot have an empty field name.'); + } + + if (strpos($field, '.') === false) { + return '{{' . $this->tableName . '}}.{{' . $field . '}}'; + } + + return $field; + } } diff --git a/src/PHPCensor/Store/BuildErrorWriter.php b/src/PHPCensor/Store/BuildErrorWriter.php index b104613a..df03a369 100644 --- a/src/PHPCensor/Store/BuildErrorWriter.php +++ b/src/PHPCensor/Store/BuildErrorWriter.php @@ -5,7 +5,6 @@ namespace PHPCensor\Store; use b8\Config; use b8\Database; use PHPCensor\Model\BuildError; -use b8\Store\Factory; /** * Class BuildErrorWriter diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index be3ad4e8..5edb0ae7 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -3,7 +3,6 @@ namespace PHPCensor\Store; use b8\Database; -use b8\Store\Factory; use PHPCensor\Model\Build; use b8\Exception\HttpException; use PHPCensor\Model\BuildMeta; diff --git a/src/B8Framework/Store/Factory.php b/src/PHPCensor/Store/Factory.php similarity index 55% rename from src/B8Framework/Store/Factory.php rename to src/PHPCensor/Store/Factory.php index fe9dfb21..3c516109 100644 --- a/src/B8Framework/Store/Factory.php +++ b/src/PHPCensor/Store/Factory.php @@ -1,20 +1,20 @@ loadStore($storeName, $namespace); + return $factory->loadStore($storeName); } protected function __construct() @@ -48,19 +47,15 @@ class Factory /** * @param string $store - * @param string $namespace * - * @return \b8\Store; + * @return Store; */ - public function loadStore($store, $namespace = null) + public function loadStore($store) { if (!isset($this->loadedStores[$store])) { - $namespace = is_null($namespace) - ? Config::getInstance()->get('b8.app.namespace') - : $namespace; + $class = 'PHPCensor\\Store\\' . $store . 'Store'; + $obj = new $class(); - $class = $namespace . '\\Store\\' . $store . 'Store'; - $obj = new $class(); $this->loadedStores[$store] = $obj; } diff --git a/src/PHPCensor/View.php b/src/PHPCensor/View.php index dcb4cb38..544f12e8 100644 --- a/src/PHPCensor/View.php +++ b/src/PHPCensor/View.php @@ -3,7 +3,7 @@ namespace PHPCensor; use b8\Config; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use PHPCensor\Model\User; use PHPCensor\Store\UserStore; diff --git a/src/PHPCensor/Worker/BuildWorker.php b/src/PHPCensor/Worker/BuildWorker.php index 558834e1..b3ae6ba7 100644 --- a/src/PHPCensor/Worker/BuildWorker.php +++ b/src/PHPCensor/Worker/BuildWorker.php @@ -2,7 +2,7 @@ namespace PHPCensor\Worker; -use b8\Store\Factory; +use PHPCensor\Store\Factory; use Monolog\Logger; use Pheanstalk\Job; use Pheanstalk\Pheanstalk; diff --git a/tests/PHPCensor/Model/BuildTest.php b/tests/PHPCensor/Model/BuildTest.php index ccd76505..57817e45 100644 --- a/tests/PHPCensor/Model/BuildTest.php +++ b/tests/PHPCensor/Model/BuildTest.php @@ -59,11 +59,9 @@ class BuildTest extends \PHPUnit\Framework\TestCase $build = new Build(); $build->setLog('log'); - self::assertEquals('log', $build->getLog()); $build->setLog(null); - self::assertEquals(null, $build->getLog()); try { @@ -74,6 +72,27 @@ class BuildTest extends \PHPUnit\Framework\TestCase $e->getMessage() ); } + + $build->setSource(Build::SOURCE_WEBHOOK_PULL_REQUEST); + self::assertEquals(Build::SOURCE_WEBHOOK_PULL_REQUEST, $build->getSource()); + + try { + $build->setSource('5'); + } catch (ValidationException $e) { + self::assertEquals( + 'Column "source" must be an integer.', + $e->getMessage() + ); + } + + try { + $build->setId(null); + } catch (ValidationException $e) { + self::assertEquals( + 'Column "id" must not be null.', + $e->getMessage() + ); + } } public function testExecute_TestBaseBuildDefaults() diff --git a/tests/PHPCensor/Plugin/EmailTest.php b/tests/PHPCensor/Plugin/EmailTest.php index c71cf53d..60cd4fa0 100644 --- a/tests/PHPCensor/Plugin/EmailTest.php +++ b/tests/PHPCensor/Plugin/EmailTest.php @@ -3,6 +3,7 @@ namespace Tests\PHPCensor\Plugin; use b8\Config; +use PHPCensor\Plugin; use PHPCensor\Plugin\Email as EmailPlugin; use PHPCensor\Model\Build; @@ -161,7 +162,9 @@ class EmailTest extends \PHPUnit\Framework\TestCase public function testBuildsBasicEmails() { - $this->loadEmailPluginWithOptions(['addresses' => ['test-receiver@example.com']], Build::STATUS_SUCCESS); + $this->loadEmailPluginWithOptions([ + 'addresses' => ['test-receiver@example.com'] + ], Build::STATUS_SUCCESS); $this->testedEmailPlugin->execute(); @@ -170,7 +173,9 @@ class EmailTest extends \PHPUnit\Framework\TestCase public function testBuildsDefaultEmails() { - $this->loadEmailPluginWithOptions(['default_mailto_address' => 'default-mailto-address@example.com'], Build::STATUS_SUCCESS); + $this->loadEmailPluginWithOptions([ + 'default_mailto_address' => 'default-mailto-address@example.com' + ], Build::STATUS_SUCCESS); $this->testedEmailPlugin->execute(); @@ -179,7 +184,9 @@ class EmailTest extends \PHPUnit\Framework\TestCase public function testExecute_UniqueRecipientsFromWithCommitter() { - $this->loadEmailPluginWithOptions(['addresses' => ['test-receiver@example.com', 'test-receiver2@example.com']]); + $this->loadEmailPluginWithOptions([ + 'addresses' => ['test-receiver@example.com', 'test-receiver2@example.com'] + ]); $returnValue = $this->testedEmailPlugin->execute(); self::assertTrue($returnValue); @@ -283,6 +290,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase Build::STATUS_SUCCESS ); + self::assertEquals('local', $this->testedEmailPlugin->getPriorityPath()); + $this->testedEmailPlugin->execute(); self::assertContains('Passing', $this->message['subject']); @@ -293,11 +302,14 @@ class EmailTest extends \PHPUnit\Framework\TestCase { $this->loadEmailPluginWithOptions( [ - 'addresses' => ['test-receiver@example.com'] + 'addresses' => ['test-receiver@example.com'], + 'priority_path' => 'global', ], Build::STATUS_FAILED ); + self::assertEquals('global', $this->testedEmailPlugin->getPriorityPath()); + $this->testedEmailPlugin->execute(); self::assertContains('Failing', $this->message['subject']); @@ -308,12 +320,15 @@ class EmailTest extends \PHPUnit\Framework\TestCase { $this->loadEmailPluginWithOptions( [ - 'addresses' => ['test-receiver@example.com'] + 'addresses' => ['test-receiver@example.com'], + 'priority_path' => 'system', ], Build::STATUS_FAILED, 1 ); + self::assertEquals('system', $this->testedEmailPlugin->getPriorityPath()); + $returnValue = $this->testedEmailPlugin->execute(); self::assertEquals(true, $returnValue); @@ -323,14 +338,19 @@ class EmailTest extends \PHPUnit\Framework\TestCase { $this->loadEmailPluginWithOptions( [ - 'addresses' => ['test-receiver@example.com'] + 'addresses' => ['test-receiver@example.com'], + 'priority_path' => 'Global', ], Build::STATUS_FAILED, 0 ); + self::assertEquals('local', $this->testedEmailPlugin->getPriorityPath()); + $returnValue = $this->testedEmailPlugin->execute(); self::assertEquals(false, $returnValue); + + self::assertEquals('', Plugin::pluginName()); } } diff --git a/tests/B8Framework/StoreMysqlTest.php b/tests/PHPCensor/StoreMysqlTest.php similarity index 95% rename from tests/B8Framework/StoreMysqlTest.php rename to tests/PHPCensor/StoreMysqlTest.php index c6697044..26235ed5 100755 --- a/tests/B8Framework/StoreMysqlTest.php +++ b/tests/PHPCensor/StoreMysqlTest.php @@ -1,13 +1,13 @@ getWhere([], 3, 1, ['id' => 'DESC']); self::assertEquals(7, $data['count']); @@ -190,7 +190,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase public function testSaveByInsert() { - $testStore = Factory::getStore('ProjectGroup', 'PHPCensor'); + $testStore = Factory::getStore('ProjectGroup'); $model = new ProjectGroup(); $model->setTitle('group 8'); @@ -205,7 +205,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase public function testSaveByUpdate() { - $testStore = Factory::getStore('ProjectGroup', 'PHPCensor'); + $testStore = Factory::getStore('ProjectGroup'); $model = $testStore->getByPrimaryKey(7); $model->setTitle('group 100'); @@ -243,7 +243,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase public function testDelete() { - $testStore = Factory::getStore('ProjectGroup', 'PHPCensor'); + $testStore = Factory::getStore('ProjectGroup'); $model = $testStore->getByPrimaryKey(5); $testStore->delete($model); diff --git a/tests/B8Framework/StorePostgresqlTest.php b/tests/PHPCensor/StorePostgresqlTest.php similarity index 96% rename from tests/B8Framework/StorePostgresqlTest.php rename to tests/PHPCensor/StorePostgresqlTest.php index dfb07921..1bfb7973 100755 --- a/tests/B8Framework/StorePostgresqlTest.php +++ b/tests/PHPCensor/StorePostgresqlTest.php @@ -1,10 +1,10 @@ getWhere([], 3, 1, ['id' => 'DESC']); self::assertEquals(7, $data['count']); @@ -181,7 +181,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase ALTER SEQUENCE "project_group_id_seq" RESTART WITH 8; '); - $testStore = Factory::getStore('ProjectGroup', 'PHPCensor'); + $testStore = Factory::getStore('ProjectGroup'); $model = new ProjectGroup(); $model->setTitle('group 8'); @@ -200,7 +200,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase ALTER SEQUENCE "project_group_id_seq" RESTART WITH 8; '); - $testStore = Factory::getStore('ProjectGroup', 'PHPCensor'); + $testStore = Factory::getStore('ProjectGroup'); $model = $testStore->getByPrimaryKey(7); $model->setTitle('group 100'); @@ -238,7 +238,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase public function testDelete() { - $testStore = Factory::getStore('ProjectGroup', 'PHPCensor'); + $testStore = Factory::getStore('ProjectGroup'); $model = $testStore->getByPrimaryKey(5); $testStore->delete($model); From e23ad3237a9196a18717bdf174557dbab47ceac0 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 15:34:19 +0700 Subject: [PATCH 05/28] Refactored Database. --- src/B8Framework/Controller.php | 1 + src/{B8Framework => PHPCensor}/Database.php | 6 ++++-- src/PHPCensor/Plugin/Mysql.php | 2 +- src/PHPCensor/Store.php | 2 -- src/PHPCensor/Store/BuildErrorStore.php | 2 +- src/PHPCensor/Store/BuildErrorWriter.php | 2 +- src/PHPCensor/Store/BuildMetaStore.php | 2 +- src/PHPCensor/Store/BuildStore.php | 2 +- src/PHPCensor/Store/EnvironmentStore.php | 2 +- src/PHPCensor/Store/ProjectGroupStore.php | 2 +- src/PHPCensor/Store/ProjectStore.php | 2 +- src/PHPCensor/Store/UserStore.php | 2 +- tests/{B8Framework => PHPCensor}/DatabaseMysqlTest.php | 10 +++++----- .../DatabasePostgresqlTest.php | 10 +++++----- tests/PHPCensor/StoreMysqlTest.php | 2 +- tests/PHPCensor/StorePostgresqlTest.php | 2 +- 16 files changed, 26 insertions(+), 25 deletions(-) rename src/{B8Framework => PHPCensor}/Database.php (98%) rename tests/{B8Framework => PHPCensor}/DatabaseMysqlTest.php (95%) rename tests/{B8Framework => PHPCensor}/DatabasePostgresqlTest.php (95%) diff --git a/src/B8Framework/Controller.php b/src/B8Framework/Controller.php index 325271b8..e199f5ad 100644 --- a/src/B8Framework/Controller.php +++ b/src/B8Framework/Controller.php @@ -4,6 +4,7 @@ namespace b8; use b8\Http\Request; use b8\Http\Response; +use PHPCensor\View; abstract class Controller { diff --git a/src/B8Framework/Database.php b/src/PHPCensor/Database.php similarity index 98% rename from src/B8Framework/Database.php rename to src/PHPCensor/Database.php index 996076ba..3decd58b 100644 --- a/src/B8Framework/Database.php +++ b/src/PHPCensor/Database.php @@ -1,6 +1,8 @@ getDetails(); @@ -168,8 +168,8 @@ class DatabaseMysqlTest extends \PHPUnit_Extensions_Database_TestCase $writeConnection = Database::getConnection('write'); $readConnection = Database::getConnection('read'); - self::assertInstanceOf('\b8\Database', $writeConnection); - self::assertInstanceOf('\b8\Database', $readConnection); + self::assertInstanceOf('\PHPCensor\Database', $writeConnection); + self::assertInstanceOf('\PHPCensor\Database', $readConnection); self::assertEquals('mysql:host=localhost;port=3306;dbname=b8_test', $readConnection->getDsn()); } diff --git a/tests/B8Framework/DatabasePostgresqlTest.php b/tests/PHPCensor/DatabasePostgresqlTest.php similarity index 95% rename from tests/B8Framework/DatabasePostgresqlTest.php rename to tests/PHPCensor/DatabasePostgresqlTest.php index 6ccee80f..721af120 100755 --- a/tests/B8Framework/DatabasePostgresqlTest.php +++ b/tests/PHPCensor/DatabasePostgresqlTest.php @@ -3,7 +3,7 @@ namespace Tests\b8; use b8\Config; -use b8\Database; +use PHPCensor\Database; class DatabasePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase { @@ -117,8 +117,8 @@ class DatabasePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase $writeConnection = Database::getConnection('write'); $readConnection = Database::getConnection('read'); - self::assertInstanceOf('\b8\Database', $writeConnection); - self::assertInstanceOf('\b8\Database', $readConnection); + self::assertInstanceOf('\PHPCensor\Database', $writeConnection); + self::assertInstanceOf('\PHPCensor\Database', $readConnection); $writeDetails = $writeConnection->getDetails(); @@ -168,8 +168,8 @@ class DatabasePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase $writeConnection = Database::getConnection('write'); $readConnection = Database::getConnection('read'); - self::assertInstanceOf('\b8\Database', $writeConnection); - self::assertInstanceOf('\b8\Database', $readConnection); + self::assertInstanceOf('\PHPCensor\Database', $writeConnection); + self::assertInstanceOf('\PHPCensor\Database', $readConnection); self::assertEquals('pgsql:host=localhost;port=5432;dbname=b8_test', $readConnection->getDsn()); } diff --git a/tests/PHPCensor/StoreMysqlTest.php b/tests/PHPCensor/StoreMysqlTest.php index 26235ed5..18f7e3b2 100755 --- a/tests/PHPCensor/StoreMysqlTest.php +++ b/tests/PHPCensor/StoreMysqlTest.php @@ -3,7 +3,7 @@ namespace Tests\PHPCensor; use b8\Config; -use b8\Database; +use PHPCensor\Database; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; use PHPCensor\Model\ProjectGroup; diff --git a/tests/PHPCensor/StorePostgresqlTest.php b/tests/PHPCensor/StorePostgresqlTest.php index 1bfb7973..fd2f26f7 100755 --- a/tests/PHPCensor/StorePostgresqlTest.php +++ b/tests/PHPCensor/StorePostgresqlTest.php @@ -3,7 +3,7 @@ namespace Tests\PHPCensor; use b8\Config; -use b8\Database; +use PHPCensor\Database; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; use PHPCensor\Model\ProjectGroup; From dd9f43b7dd695fad45c756d6733e6ce9a3c55c5d Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 15:56:02 +0700 Subject: [PATCH 06/28] Refactored Config. --- bootstrap.php | 2 +- src/B8Framework/Application.php | 1 + src/B8Framework/Controller.php | 1 + src/B8Framework/Form/Element.php | 2 +- src/B8Framework/Http/Router.php | 2 +- src/PHPCensor/Application.php | 2 +- src/PHPCensor/Builder.php | 1 - src/PHPCensor/Command/InstallCommand.php | 2 +- src/PHPCensor/Command/RunCommand.php | 2 +- src/PHPCensor/Command/WorkerCommand.php | 2 +- src/{B8Framework => PHPCensor}/Config.php | 4 ++-- src/PHPCensor/Console/Application.php | 2 +- src/PHPCensor/Controller.php | 1 - src/PHPCensor/Controller/HomeController.php | 4 ++-- src/PHPCensor/Controller/UserController.php | 6 +++--- src/PHPCensor/Controller/WebhookController.php | 2 +- src/PHPCensor/Database.php | 2 -- src/PHPCensor/Helper/Bitbucket.php | 2 +- src/PHPCensor/Helper/Email.php | 8 ++++---- src/PHPCensor/Helper/Github.php | 2 +- src/PHPCensor/Helper/Lang.php | 2 +- src/PHPCensor/Helper/SshKey.php | 2 +- src/PHPCensor/Model/Build/BitbucketBuild.php | 2 +- src/PHPCensor/Model/Build/GithubBuild.php | 2 +- src/PHPCensor/Model/User.php | 2 +- src/PHPCensor/Security/Authentication/Service.php | 2 +- src/PHPCensor/Service/BuildService.php | 2 +- src/PHPCensor/Store/BuildErrorWriter.php | 2 +- src/PHPCensor/View.php | 1 - tests/B8Framework/FormTest.php | 2 +- tests/PHPCensor/Controller/WebhookControllerTest.php | 2 +- tests/PHPCensor/DatabaseMysqlTest.php | 2 +- tests/PHPCensor/DatabasePostgresqlTest.php | 2 +- tests/PHPCensor/Plugin/EmailTest.php | 2 +- tests/PHPCensor/StoreMysqlTest.php | 2 +- tests/PHPCensor/StorePostgresqlTest.php | 2 +- tests/bootstrap.php | 2 +- 37 files changed, 40 insertions(+), 43 deletions(-) rename src/{B8Framework => PHPCensor}/Config.php (98%) diff --git a/bootstrap.php b/bootstrap.php index 628eb8de..7016a321 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -32,7 +32,7 @@ $conf['b8']['app']['namespace'] = 'PHPCensor'; $conf['b8']['app']['default_controller'] = 'Home'; $conf['b8']['view']['path'] = SRC_DIR . 'View/'; -$config = new b8\Config($conf); +$config = new PHPCensor\Config($conf); $configFile = APP_DIR . 'config.yml'; if (file_exists($configFile)) { diff --git a/src/B8Framework/Application.php b/src/B8Framework/Application.php index d90e8def..cf206023 100644 --- a/src/B8Framework/Application.php +++ b/src/B8Framework/Application.php @@ -6,6 +6,7 @@ use b8\Exception\HttpException\NotFoundException; use b8\Http\Response; use b8\Http\Request; use b8\Http\Router; +use PHPCensor\Config; class Application { diff --git a/src/B8Framework/Controller.php b/src/B8Framework/Controller.php index e199f5ad..007a38d4 100644 --- a/src/B8Framework/Controller.php +++ b/src/B8Framework/Controller.php @@ -5,6 +5,7 @@ namespace b8; use b8\Http\Request; use b8\Http\Response; use PHPCensor\View; +use PHPCensor\Config; abstract class Controller { diff --git a/src/B8Framework/Form/Element.php b/src/B8Framework/Form/Element.php index 2d89f80d..a3542334 100644 --- a/src/B8Framework/Form/Element.php +++ b/src/B8Framework/Form/Element.php @@ -3,7 +3,7 @@ namespace b8\Form; use PHPCensor\View; -use b8\Config; +use PHPCensor\Config; abstract class Element { diff --git a/src/B8Framework/Http/Router.php b/src/B8Framework/Http/Router.php index d0653241..4ba1f174 100644 --- a/src/B8Framework/Http/Router.php +++ b/src/B8Framework/Http/Router.php @@ -3,7 +3,7 @@ namespace b8\Http; use b8\Application; -use b8\Config; +use PHPCensor\Config; class Router { diff --git a/src/PHPCensor/Application.php b/src/PHPCensor/Application.php index d2a1f141..016910de 100644 --- a/src/PHPCensor/Application.php +++ b/src/PHPCensor/Application.php @@ -151,7 +151,7 @@ class Application extends b8\Application */ protected function shouldSkipAuth() { - $config = b8\Config::getInstance(); + $config = Config::getInstance(); $disableAuth = (bool)$config->get('php-censor.security.disable_auth', false); $defaultUserId = (integer)$config->get('php-censor.security.default_user_id', 1); diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index a0df4ae9..64b476f9 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -7,7 +7,6 @@ use PHPCensor\Helper\MailerFactory; use PHPCensor\Logging\BuildLogger; use PHPCensor\Model\Build; use PHPCensor\Store\Factory; -use b8\Config; use PHPCensor\Store\BuildErrorWriter; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; diff --git a/src/PHPCensor/Command/InstallCommand.php b/src/PHPCensor/Command/InstallCommand.php index 993d0437..e1210ebe 100644 --- a/src/PHPCensor/Command/InstallCommand.php +++ b/src/PHPCensor/Command/InstallCommand.php @@ -5,7 +5,7 @@ namespace PHPCensor\Command; use Exception; use PDO; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Store\Factory; use PHPCensor\Model\ProjectGroup; use PHPCensor\Store\UserStore; diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 81885b4a..bc613f29 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -2,7 +2,7 @@ namespace PHPCensor\Command; -use b8\Config; +use PHPCensor\Config; use Monolog\Logger; use PHPCensor\Logging\BuildDBLogHandler; use PHPCensor\Logging\LoggedBuildContextTidier; diff --git a/src/PHPCensor/Command/WorkerCommand.php b/src/PHPCensor/Command/WorkerCommand.php index 644e9394..81f25525 100644 --- a/src/PHPCensor/Command/WorkerCommand.php +++ b/src/PHPCensor/Command/WorkerCommand.php @@ -2,7 +2,7 @@ namespace PHPCensor\Command; -use b8\Config; +use PHPCensor\Config; use Monolog\Logger; use PHPCensor\Logging\OutputLogHandler; use PHPCensor\Worker\BuildWorker; diff --git a/src/B8Framework/Config.php b/src/PHPCensor/Config.php similarity index 98% rename from src/B8Framework/Config.php rename to src/PHPCensor/Config.php index fa3d6c1b..89ec30c7 100644 --- a/src/B8Framework/Config.php +++ b/src/PHPCensor/Config.php @@ -1,11 +1,11 @@ [], 'right' => [], ]; - $widgets_config = b8\Config::getInstance()->get('php-censor.dashboard_widgets', [ + $widgets_config = Config::getInstance()->get('php-censor.dashboard_widgets', [ 'all_projects' => [ 'side' => 'left', ], diff --git a/src/PHPCensor/Controller/UserController.php b/src/PHPCensor/Controller/UserController.php index 1ad35a69..2395754f 100644 --- a/src/PHPCensor/Controller/UserController.php +++ b/src/PHPCensor/Controller/UserController.php @@ -2,7 +2,7 @@ namespace PHPCensor\Controller; -use b8; +use PHPCensor\Config; use b8\Exception\HttpException\NotFoundException; use b8\Form; use PHPCensor\Controller; @@ -116,7 +116,7 @@ class UserController extends Controller $language->setLabel(Lang::get('language')); $language->setRequired(true); $language->setOptions(array_merge( - [null => Lang::get('default') . ' (' . b8\Config::getInstance()->get('php-censor.language') . ')'], + [null => Lang::get('default') . ' (' . Config::getInstance()->get('php-censor.language') . ')'], Lang::getLanguageOptions()) ); $language->setValue($user->getLanguage()); @@ -128,7 +128,7 @@ class UserController extends Controller $perPage->setLabel(Lang::get('per_page')); $perPage->setRequired(true); $perPage->setOptions([ - null => Lang::get('default') . ' (' . b8\Config::getInstance()->get('php-censor.per_page') . ')', + null => Lang::get('default') . ' (' . Config::getInstance()->get('php-censor.per_page') . ')', 10 => 10, 25 => 25, 50 => 50, diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 49a25266..4102ce3b 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -12,7 +12,7 @@ use PHPCensor\Service\BuildService; use PHPCensor\Store\BuildStore; use PHPCensor\Store\ProjectStore; use b8\Controller; -use b8\Config; +use PHPCensor\Config; use b8\Exception\HttpException\NotFoundException; use PHPCensor\Store\Factory; diff --git a/src/PHPCensor/Database.php b/src/PHPCensor/Database.php index 3decd58b..9091f8bb 100644 --- a/src/PHPCensor/Database.php +++ b/src/PHPCensor/Database.php @@ -2,8 +2,6 @@ namespace PHPCensor; -use b8\Config; - class Database extends \PDO { const MYSQL_TYPE = 'mysql'; diff --git a/src/PHPCensor/Helper/Bitbucket.php b/src/PHPCensor/Helper/Bitbucket.php index a6fe475c..36f869f1 100644 --- a/src/PHPCensor/Helper/Bitbucket.php +++ b/src/PHPCensor/Helper/Bitbucket.php @@ -2,7 +2,7 @@ namespace PHPCensor\Helper; -use b8\Config; +use PHPCensor\Config; use GuzzleHttp\Client; /** diff --git a/src/PHPCensor/Helper/Email.php b/src/PHPCensor/Helper/Email.php index dd5eb78a..b96d3265 100644 --- a/src/PHPCensor/Helper/Email.php +++ b/src/PHPCensor/Helper/Email.php @@ -2,7 +2,7 @@ namespace PHPCensor\Helper; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Builder; /** @@ -99,13 +99,13 @@ class Email 'php-censor.email_settings.from_address', self::DEFAULT_FROM ); - + if (strpos($from, '<') === false) { return (string)$from; } - + preg_match('#^(.*?)<(.*)>$#ui', $from, $fromParts); - + return [$fromParts[2] => $fromParts[1]]; } diff --git a/src/PHPCensor/Helper/Github.php b/src/PHPCensor/Helper/Github.php index 0f8874a3..1bcc041b 100644 --- a/src/PHPCensor/Helper/Github.php +++ b/src/PHPCensor/Helper/Github.php @@ -2,7 +2,7 @@ namespace PHPCensor\Helper; -use b8\Config; +use PHPCensor\Config; use GuzzleHttp\Client; use Symfony\Component\Cache\Simple\FilesystemCache; diff --git a/src/PHPCensor/Helper/Lang.php b/src/PHPCensor/Helper/Lang.php index 5322ecda..831ac9d0 100644 --- a/src/PHPCensor/Helper/Lang.php +++ b/src/PHPCensor/Helper/Lang.php @@ -2,7 +2,7 @@ namespace PHPCensor\Helper; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Store\Factory; use PHPCensor\Store\UserStore; diff --git a/src/PHPCensor/Helper/SshKey.php b/src/PHPCensor/Helper/SshKey.php index b532f181..efce7298 100644 --- a/src/PHPCensor/Helper/SshKey.php +++ b/src/PHPCensor/Helper/SshKey.php @@ -2,7 +2,7 @@ namespace PHPCensor\Helper; -use b8\Config; +use PHPCensor\Config; /** * Helper class for dealing with SSH keys. diff --git a/src/PHPCensor/Model/Build/BitbucketBuild.php b/src/PHPCensor/Model/Build/BitbucketBuild.php index 3b29d38d..412e28d7 100644 --- a/src/PHPCensor/Model/Build/BitbucketBuild.php +++ b/src/PHPCensor/Model/Build/BitbucketBuild.php @@ -6,7 +6,7 @@ use GuzzleHttp\Client; use PHPCensor\Builder; use PHPCensor\Helper\Bitbucket; use PHPCensor\Helper\Diff; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Model\Build; use PHPCensor\Model\BuildError; diff --git a/src/PHPCensor/Model/Build/GithubBuild.php b/src/PHPCensor/Model/Build/GithubBuild.php index b3968b93..52fcaf9f 100644 --- a/src/PHPCensor/Model/Build/GithubBuild.php +++ b/src/PHPCensor/Model/Build/GithubBuild.php @@ -6,7 +6,7 @@ use GuzzleHttp\Client; use PHPCensor\Builder; use PHPCensor\Helper\Diff; use PHPCensor\Helper\Github; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Model\Build; use PHPCensor\Model\BuildError; diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index 405666be..2bba224c 100644 --- a/src/PHPCensor/Model/User.php +++ b/src/PHPCensor/Model/User.php @@ -2,7 +2,7 @@ namespace PHPCensor\Model; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Model; /** diff --git a/src/PHPCensor/Security/Authentication/Service.php b/src/PHPCensor/Security/Authentication/Service.php index 7b5aa0ef..da8e7d5a 100644 --- a/src/PHPCensor/Security/Authentication/Service.php +++ b/src/PHPCensor/Security/Authentication/Service.php @@ -2,7 +2,7 @@ namespace PHPCensor\Security\Authentication; -use b8\Config; +use PHPCensor\Config; /** * Authentication facade. diff --git a/src/PHPCensor/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index c583cec8..aa59aaca 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -2,7 +2,7 @@ namespace PHPCensor\Service; -use b8\Config; +use PHPCensor\Config; use Pheanstalk\Pheanstalk; use Pheanstalk\PheanstalkInterface; use PHPCensor\BuildFactory; diff --git a/src/PHPCensor/Store/BuildErrorWriter.php b/src/PHPCensor/Store/BuildErrorWriter.php index 3fe2d5ed..5ec6d3d7 100644 --- a/src/PHPCensor/Store/BuildErrorWriter.php +++ b/src/PHPCensor/Store/BuildErrorWriter.php @@ -2,7 +2,7 @@ namespace PHPCensor\Store; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Database; use PHPCensor\Model\BuildError; diff --git a/src/PHPCensor/View.php b/src/PHPCensor/View.php index 544f12e8..1e06d1ac 100644 --- a/src/PHPCensor/View.php +++ b/src/PHPCensor/View.php @@ -2,7 +2,6 @@ namespace PHPCensor; -use b8\Config; use PHPCensor\Store\Factory; use PHPCensor\Model\User; use PHPCensor\Store\UserStore; diff --git a/tests/B8Framework/FormTest.php b/tests/B8Framework/FormTest.php index e9def9d9..9b59e465 100755 --- a/tests/B8Framework/FormTest.php +++ b/tests/B8Framework/FormTest.php @@ -3,7 +3,7 @@ namespace Tests\b8; use b8\Form; -use b8\Config; +use PHPCensor\Config; class FormTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/PHPCensor/Controller/WebhookControllerTest.php b/tests/PHPCensor/Controller/WebhookControllerTest.php index 43e81f60..4ff3a5b3 100644 --- a/tests/PHPCensor/Controller/WebhookControllerTest.php +++ b/tests/PHPCensor/Controller/WebhookControllerTest.php @@ -9,7 +9,7 @@ class WebhookControllerTest extends \PHPUnit\Framework\TestCase public function test_wrong_action_name_return_json_with_error() { $webController = new WebhookController( - $this->prophesize('b8\Config')->reveal(), + $this->prophesize('PHPCensor\Config')->reveal(), $this->prophesize('b8\Http\Request')->reveal(), $this->prophesize('b8\Http\Response')->reveal() ); diff --git a/tests/PHPCensor/DatabaseMysqlTest.php b/tests/PHPCensor/DatabaseMysqlTest.php index 6a52b2f2..6e4d7613 100755 --- a/tests/PHPCensor/DatabaseMysqlTest.php +++ b/tests/PHPCensor/DatabaseMysqlTest.php @@ -2,7 +2,7 @@ namespace Tests\b8; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Database; class DatabaseMysqlTest extends \PHPUnit_Extensions_Database_TestCase diff --git a/tests/PHPCensor/DatabasePostgresqlTest.php b/tests/PHPCensor/DatabasePostgresqlTest.php index 721af120..e89b0c18 100755 --- a/tests/PHPCensor/DatabasePostgresqlTest.php +++ b/tests/PHPCensor/DatabasePostgresqlTest.php @@ -2,7 +2,7 @@ namespace Tests\b8; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Database; class DatabasePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase diff --git a/tests/PHPCensor/Plugin/EmailTest.php b/tests/PHPCensor/Plugin/EmailTest.php index 60cd4fa0..315424c1 100644 --- a/tests/PHPCensor/Plugin/EmailTest.php +++ b/tests/PHPCensor/Plugin/EmailTest.php @@ -2,7 +2,7 @@ namespace Tests\PHPCensor\Plugin; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Plugin; use PHPCensor\Plugin\Email as EmailPlugin; use PHPCensor\Model\Build; diff --git a/tests/PHPCensor/StoreMysqlTest.php b/tests/PHPCensor/StoreMysqlTest.php index 18f7e3b2..0bd3981f 100755 --- a/tests/PHPCensor/StoreMysqlTest.php +++ b/tests/PHPCensor/StoreMysqlTest.php @@ -2,7 +2,7 @@ namespace Tests\PHPCensor; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Database; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; diff --git a/tests/PHPCensor/StorePostgresqlTest.php b/tests/PHPCensor/StorePostgresqlTest.php index fd2f26f7..5f3bef70 100755 --- a/tests/PHPCensor/StorePostgresqlTest.php +++ b/tests/PHPCensor/StorePostgresqlTest.php @@ -2,7 +2,7 @@ namespace Tests\PHPCensor; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Database; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d07365a4..055f8d1d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -33,7 +33,7 @@ $conf['b8']['app']['default_controller'] = 'Home'; $conf['b8']['view']['path'] = SRC_DIR . 'View/'; $conf['php-censor']['url'] = 'http://php-censor.local'; -$config = new b8\Config($conf); +$config = new PHPCensor\Config($conf); if (!defined('APP_URL')) { define('APP_URL', $config->get('php-censor.url', '') . '/'); From d1c37fc2936a6a00bb9a8a7a0516448bc4c082cd Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 16:15:21 +0700 Subject: [PATCH 07/28] Refactored Controller. --- src/B8Framework/Application.php | 1 + src/B8Framework/Controller.php | 128 ------------------ src/PHPCensor/Controller.php | 93 ++++++++++++- .../Controller/WebhookController.php | 18 ++- 4 files changed, 104 insertions(+), 136 deletions(-) delete mode 100644 src/B8Framework/Controller.php diff --git a/src/B8Framework/Application.php b/src/B8Framework/Application.php index cf206023..9094eac4 100644 --- a/src/B8Framework/Application.php +++ b/src/B8Framework/Application.php @@ -7,6 +7,7 @@ use b8\Http\Response; use b8\Http\Request; use b8\Http\Router; use PHPCensor\Config; +use PHPCensor\Controller; class Application { diff --git a/src/B8Framework/Controller.php b/src/B8Framework/Controller.php deleted file mode 100644 index 007a38d4..00000000 --- a/src/B8Framework/Controller.php +++ /dev/null @@ -1,128 +0,0 @@ -config = $config; - $this->request = $request; - $this->response = $response; - } - - /** - * @param string $name - * - * @return boolean - */ - public function hasAction($name) - { - if (method_exists($this, $name)) { - return true; - } - - if (method_exists($this, '__call')) { - return true; - } - - return false; - } - - /** - * Handles an action on this controller and returns a Response object. - * - * @param string $action - * @param array $actionParams - * - * @return Response - */ - public function handleAction($action, $actionParams) - { - return call_user_func_array([$this, $action], $actionParams); - } - - /** - * Initialise the controller. - */ - abstract public function init(); - - /** - * Get a hash of incoming request parameters ($_GET, $_POST) - * - * @return array - */ - public function getParams() - { - return $this->request->getParams(); - } - - /** - * Get a specific incoming request parameter. - * - * @param string $key - * @param mixed $default Default return value (if key does not exist) - * - * @return mixed - */ - public function getParam($key, $default = null) - { - return $this->request->getParam($key, $default); - } - - /** - * Change the value of an incoming request parameter. - * - * @param string $key - * @param mixed $value - */ - public function setParam($key, $value) - { - $this->request->setParam($key, $value); - } - - /** - * Remove an incoming request parameter. - * - * @param string $key - */ - public function unsetParam($key) - { - $this->request->unsetParam($key); - } -} diff --git a/src/PHPCensor/Controller.php b/src/PHPCensor/Controller.php index 9df17521..c2905ba9 100644 --- a/src/PHPCensor/Controller.php +++ b/src/PHPCensor/Controller.php @@ -9,11 +9,26 @@ use PHPCensor\Store\Factory; use PHPCensor\Model\User; use PHPCensor\Store\UserStore; -class Controller extends \b8\Controller +class Controller { /** - * @var View - */ + * @var Request + */ + protected $request; + + /** + * @var Response + */ + protected $response; + + /** + * @var Config + */ + protected $config; + + /** + * @var View + */ protected $controllerView; /** @@ -46,13 +61,17 @@ class Controller extends \b8\Controller */ public function __construct(Config $config, Request $request, Response $response) { - parent::__construct($config, $request, $response); + $this->config = $config; + $this->request = $request; + $this->response = $response; $class = explode('\\', get_class($this)); $this->className = substr(array_pop($class), 0, -10); $this->setControllerView(); - unset($_SESSION['php-censor-user']); + if (!empty($_SESSION['php-censor-user'])) { + unset($_SESSION['php-censor-user']); + } } /** @@ -90,7 +109,7 @@ class Controller extends \b8\Controller public function handleAction($action, $actionParams) { $this->setView($action); - $response = parent::handleAction($action, $actionParams); + $response = call_user_func_array([$this, $action], $actionParams); if ($response instanceof Response) { return $response; @@ -148,4 +167,66 @@ class Controller extends \b8\Controller return $userStore->getById($_SESSION['php-censor-user-id']); } + + /** + * @param string $name + * + * @return boolean + */ + public function hasAction($name) + { + if (method_exists($this, $name)) { + return true; + } + + if (method_exists($this, '__call')) { + return true; + } + + return false; + } + + /** + * Get a hash of incoming request parameters ($_GET, $_POST) + * + * @return array + */ + public function getParams() + { + return $this->request->getParams(); + } + + /** + * Get a specific incoming request parameter. + * + * @param string $key + * @param mixed $default Default return value (if key does not exist) + * + * @return mixed + */ + public function getParam($key, $default = null) + { + return $this->request->getParam($key, $default); + } + + /** + * Change the value of an incoming request parameter. + * + * @param string $key + * @param mixed $value + */ + public function setParam($key, $value) + { + $this->request->setParam($key, $value); + } + + /** + * Remove an incoming request parameter. + * + * @param string $key + */ + public function unsetParam($key) + { + $this->request->unsetParam($key); + } } diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 4102ce3b..abaae725 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -11,10 +11,12 @@ use PHPCensor\Model\Project; use PHPCensor\Service\BuildService; use PHPCensor\Store\BuildStore; use PHPCensor\Store\ProjectStore; -use b8\Controller; +use PHPCensor\Controller; use PHPCensor\Config; use b8\Exception\HttpException\NotFoundException; use PHPCensor\Store\Factory; +use b8\Http\Request; +use b8\Http\Response; /** * Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc. @@ -42,6 +44,18 @@ class WebhookController extends Controller */ protected $buildService; + /** + * @param Config $config + * @param Request $request + * @param Response $response + */ + public function __construct(Config $config, Request $request, Response $response) + { + $this->config = $config; + $this->request = $request; + $this->response = $response; + } + /** * Initialise the controller, set up stores and services. */ @@ -63,7 +77,7 @@ class WebhookController extends Controller { $response = new b8\Http\Response\JsonResponse(); try { - $data = parent::handleAction($action, $actionParams); + $data = call_user_func_array([$this, $action], $actionParams); if (isset($data['responseCode'])) { $response->setResponseCode($data['responseCode']); unset($data['responseCode']); From 69e969436d2a9659bc78f9b8407169a5dc5c20b5 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 16:28:53 +0700 Subject: [PATCH 08/28] Refactored Application. --- src/B8Framework/Application.php | 173 -------------------------------- src/B8Framework/Http/Router.php | 4 +- src/PHPCensor/Application.php | 158 +++++++++++++++++++++++++++-- 3 files changed, 154 insertions(+), 181 deletions(-) delete mode 100644 src/B8Framework/Application.php diff --git a/src/B8Framework/Application.php b/src/B8Framework/Application.php deleted file mode 100644 index 9094eac4..00000000 --- a/src/B8Framework/Application.php +++ /dev/null @@ -1,173 +0,0 @@ -config = $config; - $this->response = new Response(); - - if (!is_null($request)) { - $this->request = $request; - } else { - $this->request = new Request(); - } - - $this->router = new Router($this, $this->request, $this->config); - - if (method_exists($this, 'init')) { - $this->init(); - } - } - - /** - * @return Response - * - * @throws NotFoundException - */ - public function handleRequest() - { - $this->route = $this->router->dispatch(); - - if (!empty($this->route['callback'])) { - $callback = $this->route['callback']; - - if (!$callback($this->route, $this->response)) { - return $this->response; - } - } - - if (!$this->controllerExists($this->route)) { - throw new NotFoundException('Controller ' . $this->toPhpName($this->route['controller']) . ' does not exist!'); - } - - $action = lcfirst($this->toPhpName($this->route['action'])); - if (!$this->getController()->hasAction($action)) { - throw new NotFoundException('Controller ' . $this->toPhpName($this->route['controller']) . ' does not have action ' . $action . '!'); - } - - return $this->getController()->handleAction($action, $this->route['args']); - } - - /** - * @return Controller - */ - public function getController() - { - if (empty($this->controller)) { - $controllerClass = $this->getControllerClass($this->route); - $this->controller = $this->loadController($controllerClass); - } - - return $this->controller; - } - - /** - * @param string $class - * - * @return Controller - */ - protected function loadController($class) - { - /** @var Controller $controller */ - $controller = new $class($this->config, $this->request, $this->response); - $controller->init(); - - return $controller; - } - - /** - * @param array $route - * - * @return bool - */ - protected function controllerExists($route) - { - return class_exists($this->getControllerClass($route)); - } - - /** - * @param array $route - * - * @return string - */ - protected function getControllerClass($route) - { - $namespace = $this->toPhpName($route['namespace']); - $controller = $this->toPhpName($route['controller']); - - return $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller'; - } - - /** - * @param array $route - * - * @return boolean - */ - public function isValidRoute(array $route) - { - if ($this->controllerExists($route)) { - return true; - } - - return false; - } - - /** - * @param string $string - * - * @return string - */ - protected function toPhpName($string) - { - $string = str_replace('-', ' ', $string); - $string = ucwords($string); - $string = str_replace(' ', '', $string); - - return $string; - } -} diff --git a/src/B8Framework/Http/Router.php b/src/B8Framework/Http/Router.php index 4ba1f174..ed9fd059 100644 --- a/src/B8Framework/Http/Router.php +++ b/src/B8Framework/Http/Router.php @@ -2,7 +2,7 @@ namespace b8\Http; -use b8\Application; +use PHPCensor\Application; use PHPCensor\Config; class Router @@ -18,7 +18,7 @@ class Router protected $config; /** - * @var \b8\Application + * @var Application */ protected $application; diff --git a/src/PHPCensor/Application.php b/src/PHPCensor/Application.php index 016910de..fe2adca6 100644 --- a/src/PHPCensor/Application.php +++ b/src/PHPCensor/Application.php @@ -2,22 +2,72 @@ namespace PHPCensor; -use b8; use b8\Exception\HttpException; use b8\Http\Response; use b8\Http\Response\RedirectResponse; use PHPCensor\Store\Factory; +use b8\Exception\HttpException\NotFoundException; +use b8\Http\Request; +use b8\Http\Router; /** * @author Dan Cryer */ -class Application extends b8\Application +class Application { /** - * @var \PHPCensor\Controller + * @var array + */ + protected $route; + + /** + * @var Controller */ protected $controller; + /** + * @var Request + */ + protected $request; + + /** + * @var Response + */ + protected $response; + + /** + * @var Config + */ + protected $config; + + /** + * @var Router + */ + protected $router; + + /** + * @param Config $config + * + * @param Request|null $request + */ + public function __construct(Config $config, Request $request = null) + { + $this->config = $config; + $this->response = new Response(); + + if (!is_null($request)) { + $this->request = $request; + } else { + $this->request = new Request(); + } + + $this->router = new Router($this, $this->request, $this->config); + + if (method_exists($this, 'init')) { + $this->init(); + } + } + /** * Initialise Application - Handles session verification, routing, etc. */ @@ -66,6 +116,35 @@ class Application extends b8\Application $this->router->register($route, $opts, $routeHandler); } + /** + * @return Response + * + * @throws NotFoundException + */ + protected function handleRequestInner() + { + $this->route = $this->router->dispatch(); + + if (!empty($this->route['callback'])) { + $callback = $this->route['callback']; + + if (!$callback($this->route, $this->response)) { + return $this->response; + } + } + + if (!$this->controllerExists($this->route)) { + throw new NotFoundException('Controller ' . $this->toPhpName($this->route['controller']) . ' does not exist!'); + } + + $action = lcfirst($this->toPhpName($this->route['action'])); + if (!$this->getController()->hasAction($action)) { + throw new NotFoundException('Controller ' . $this->toPhpName($this->route['controller']) . ' does not have action ' . $action . '!'); + } + + return $this->getController()->handleAction($action, $this->route['args']); + } + /** * Handle an incoming web request. * @@ -74,7 +153,7 @@ class Application extends b8\Application public function handleRequest() { try { - $this->response = parent::handleRequest(); + $this->response = $this->handleRequestInner(); } catch (HttpException $ex) { $this->config->set('page_title', 'Error'); @@ -108,11 +187,14 @@ class Application extends b8\Application * * @param string $class * - * @return b8\Controller + * @return Controller */ protected function loadController($class) { - $controller = parent::loadController($class); + /** @var Controller $controller */ + $controller = new $class($this->config, $this->request, $this->response); + $controller->init(); + $controller->layout = new View('layout'); $controller->layout->title = 'PHP Censor'; $controller->layout->breadcrumb = []; @@ -165,4 +247,68 @@ class Application extends b8\Application return false; } + + /** + * @return Controller + */ + public function getController() + { + if (empty($this->controller)) { + $controllerClass = $this->getControllerClass($this->route); + $this->controller = $this->loadController($controllerClass); + } + + return $this->controller; + } + + /** + * @param array $route + * + * @return bool + */ + protected function controllerExists($route) + { + return class_exists($this->getControllerClass($route)); + } + + /** + * @param array $route + * + * @return string + */ + protected function getControllerClass($route) + { + $namespace = $this->toPhpName($route['namespace']); + $controller = $this->toPhpName($route['controller']); + + return $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller'; + } + + /** + * @param array $route + * + * @return boolean + */ + public function isValidRoute(array $route) + { + if ($this->controllerExists($route)) { + return true; + } + + return false; + } + + /** + * @param string $string + * + * @return string + */ + protected function toPhpName($string) + { + $string = str_replace('-', ' ', $string); + $string = ucwords($string); + $string = str_replace(' ', '', $string); + + return $string; + } } From aadfabd714253be510c5e91c4be561a8668bb93b Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 17:14:09 +0700 Subject: [PATCH 09/28] Refactored HttpExceptions. --- .../HttpException/ServerErrorException.php | 9 --------- src/PHPCensor/Application.php | 4 ++-- src/PHPCensor/Controller.php | 2 +- src/PHPCensor/Controller/BuildController.php | 3 +-- src/PHPCensor/Controller/BuildStatusController.php | 13 +++++++------ src/PHPCensor/Controller/ProjectController.php | 3 +-- src/PHPCensor/Controller/UserController.php | 2 +- src/PHPCensor/Controller/WebhookController.php | 5 ++--- .../Exception/HttpException.php | 2 +- .../HttpException/BadRequestException.php | 4 ++-- .../Exception/HttpException/ForbiddenException.php | 4 ++-- .../HttpException/NotAuthorizedException.php | 4 ++-- .../Exception/HttpException/NotFoundException.php | 4 ++-- .../HttpException/ServerErrorException.php | 9 +++++++++ .../HttpException/ValidationException.php | 4 ++-- src/PHPCensor/Model.php | 14 +++++++------- src/PHPCensor/Store/BuildErrorStore.php | 2 +- src/PHPCensor/Store/BuildMetaStore.php | 2 +- src/PHPCensor/Store/BuildStore.php | 2 +- src/PHPCensor/Store/EnvironmentStore.php | 2 +- src/PHPCensor/Store/ProjectGroupStore.php | 2 +- src/PHPCensor/Store/ProjectStore.php | 2 +- src/PHPCensor/Store/UserStore.php | 2 +- tests/PHPCensor/DatabaseMysqlTest.php | 2 +- tests/PHPCensor/DatabasePostgresqlTest.php | 2 +- .../HttpExceptionTest.php | 4 ++-- tests/PHPCensor/Model/BuildTest.php | 3 +-- 27 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 src/B8Framework/Exception/HttpException/ServerErrorException.php rename src/{B8Framework => PHPCensor}/Exception/HttpException.php (95%) rename src/{B8Framework => PHPCensor}/Exception/HttpException/BadRequestException.php (71%) rename src/{B8Framework => PHPCensor}/Exception/HttpException/ForbiddenException.php (71%) rename src/{B8Framework => PHPCensor}/Exception/HttpException/NotAuthorizedException.php (72%) rename src/{B8Framework => PHPCensor}/Exception/HttpException/NotFoundException.php (71%) create mode 100644 src/PHPCensor/Exception/HttpException/ServerErrorException.php rename src/{B8Framework => PHPCensor}/Exception/HttpException/ValidationException.php (71%) rename tests/{B8Framework => PHPCensor}/HttpExceptionTest.php (97%) diff --git a/src/B8Framework/Exception/HttpException/ServerErrorException.php b/src/B8Framework/Exception/HttpException/ServerErrorException.php deleted file mode 100644 index 34ec1e84..00000000 --- a/src/B8Framework/Exception/HttpException/ServerErrorException.php +++ /dev/null @@ -1,9 +0,0 @@ -getStatus($projectId); if (is_null($status)) { - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', '/'); return $response; @@ -182,6 +182,7 @@ class BuildStatusController extends Controller $this->response->disableLayout(); $this->response->setHeader('Content-Type', 'image/svg+xml'); $this->response->setContent($image); + return $this->response; } @@ -192,7 +193,7 @@ class BuildStatusController extends Controller * * @return string * - * @throws \b8\Exception\HttpException\NotFoundException + * @throws NotFoundException */ public function view($projectId) { diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index c222c43f..5db12a36 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -2,8 +2,7 @@ namespace PHPCensor\Controller; -use b8; -use b8\Exception\HttpException\NotFoundException; +use PHPCensor\Exception\HttpException\NotFoundException; use b8\Form; use JasonGrimes\Paginator; use PHPCensor; diff --git a/src/PHPCensor/Controller/UserController.php b/src/PHPCensor/Controller/UserController.php index 2395754f..c7df2325 100644 --- a/src/PHPCensor/Controller/UserController.php +++ b/src/PHPCensor/Controller/UserController.php @@ -3,7 +3,7 @@ namespace PHPCensor\Controller; use PHPCensor\Config; -use b8\Exception\HttpException\NotFoundException; +use PHPCensor\Exception\HttpException\NotFoundException; use b8\Form; use PHPCensor\Controller; use PHPCensor\Helper\Lang; diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index abaae725..c43e0635 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -2,7 +2,6 @@ namespace PHPCensor\Controller; -use b8; use Exception; use GuzzleHttp\Client; use PHPCensor\Helper\Lang; @@ -13,7 +12,7 @@ use PHPCensor\Store\BuildStore; use PHPCensor\Store\ProjectStore; use PHPCensor\Controller; use PHPCensor\Config; -use b8\Exception\HttpException\NotFoundException; +use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Store\Factory; use b8\Http\Request; use b8\Http\Response; @@ -75,7 +74,7 @@ class WebhookController extends Controller */ public function handleAction($action, $actionParams) { - $response = new b8\Http\Response\JsonResponse(); + $response = new Response\JsonResponse(); try { $data = call_user_func_array([$this, $action], $actionParams); if (isset($data['responseCode'])) { diff --git a/src/B8Framework/Exception/HttpException.php b/src/PHPCensor/Exception/HttpException.php similarity index 95% rename from src/B8Framework/Exception/HttpException.php rename to src/PHPCensor/Exception/HttpException.php index 4c266213..ba2637d7 100644 --- a/src/B8Framework/Exception/HttpException.php +++ b/src/PHPCensor/Exception/HttpException.php @@ -1,6 +1,6 @@ diff --git a/src/PHPCensor/Store/UserStore.php b/src/PHPCensor/Store/UserStore.php index 7d8aa55b..b397f090 100644 --- a/src/PHPCensor/Store/UserStore.php +++ b/src/PHPCensor/Store/UserStore.php @@ -4,7 +4,7 @@ namespace PHPCensor\Store; use PHPCensor\Store; use PHPCensor\Database; -use b8\Exception\HttpException; +use PHPCensor\Exception\HttpException; use PHPCensor\Model\User; /** diff --git a/tests/PHPCensor/DatabaseMysqlTest.php b/tests/PHPCensor/DatabaseMysqlTest.php index 6e4d7613..b5662cf8 100755 --- a/tests/PHPCensor/DatabaseMysqlTest.php +++ b/tests/PHPCensor/DatabaseMysqlTest.php @@ -1,6 +1,6 @@ Date: Sun, 4 Mar 2018 17:22:14 +0700 Subject: [PATCH 10/28] Refactored Http. --- public/index.php | 2 +- src/PHPCensor/Application.php | 8 ++++---- src/PHPCensor/Controller.php | 4 ++-- src/PHPCensor/Controller/BuildController.php | 7 ++++--- src/PHPCensor/Controller/BuildStatusController.php | 4 ++-- src/PHPCensor/Controller/GroupController.php | 11 +++++++---- src/PHPCensor/Controller/ProjectController.php | 6 +++--- src/PHPCensor/Controller/SessionController.php | 9 +++++---- src/PHPCensor/Controller/UserController.php | 7 ++++--- src/PHPCensor/Controller/WebhookController.php | 6 +++--- .../Controller/WidgetAllProjectsController.php | 2 +- .../Controller/WidgetBuildErrorsController.php | 2 +- .../Controller/WidgetLastBuildsController.php | 2 +- src/{B8Framework => PHPCensor}/Http/Request.php | 2 +- src/{B8Framework => PHPCensor}/Http/Response.php | 2 +- .../Http/Response/JsonResponse.php | 4 ++-- .../Http/Response/RedirectResponse.php | 4 ++-- src/{B8Framework => PHPCensor}/Http/Router.php | 2 +- tests/PHPCensor/Controller/WebhookControllerTest.php | 6 +++--- 19 files changed, 48 insertions(+), 42 deletions(-) rename src/{B8Framework => PHPCensor}/Http/Request.php (99%) rename src/{B8Framework => PHPCensor}/Http/Response.php (99%) rename src/{B8Framework => PHPCensor}/Http/Response/JsonResponse.php (88%) rename src/{B8Framework => PHPCensor}/Http/Response/RedirectResponse.php (85%) rename src/{B8Framework => PHPCensor}/Http/Router.php (99%) diff --git a/public/index.php b/public/index.php index 38cf5393..753adf5e 100644 --- a/public/index.php +++ b/public/index.php @@ -4,5 +4,5 @@ session_start(); require_once(dirname(__DIR__) . '/bootstrap.php'); -$fc = new PHPCensor\Application($config, new b8\Http\Request()); +$fc = new PHPCensor\Application($config, new PHPCensor\Http\Request()); print $fc->handleRequest(); diff --git a/src/PHPCensor/Application.php b/src/PHPCensor/Application.php index e652edb2..857cc17b 100644 --- a/src/PHPCensor/Application.php +++ b/src/PHPCensor/Application.php @@ -3,12 +3,12 @@ namespace PHPCensor; use PHPCensor\Exception\HttpException; -use b8\Http\Response; -use b8\Http\Response\RedirectResponse; +use PHPCensor\Http\Response; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Store\Factory; use PHPCensor\Exception\HttpException\NotFoundException; -use b8\Http\Request; -use b8\Http\Router; +use PHPCensor\Http\Request; +use PHPCensor\Http\Router; /** * @author Dan Cryer diff --git a/src/PHPCensor/Controller.php b/src/PHPCensor/Controller.php index fc8b4ea4..f30854ad 100644 --- a/src/PHPCensor/Controller.php +++ b/src/PHPCensor/Controller.php @@ -3,8 +3,8 @@ namespace PHPCensor; use PHPCensor\Exception\HttpException\ForbiddenException; -use b8\Http\Request; -use b8\Http\Response; +use PHPCensor\Http\Request; +use PHPCensor\Http\Response; use PHPCensor\Store\Factory; use PHPCensor\Model\User; use PHPCensor\Store\UserStore; diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index 8d28224c..7aea2daa 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -3,11 +3,12 @@ namespace PHPCensor\Controller; use PHPCensor\Exception\HttpException\NotFoundException; -use b8\Http\Response\JsonResponse; +use PHPCensor\Http\Response\JsonResponse; use JasonGrimes\Paginator; use PHPCensor\BuildFactory; use PHPCensor\Helper\AnsiConverter; use PHPCensor\Helper\Lang; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\Build; use PHPCensor\Model\User; use PHPCensor\Service\BuildService; @@ -251,7 +252,7 @@ class BuildController extends Controller $_SESSION['global_error'] = Lang::get('add_to_queue_failed'); } - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'build/view/' . $build->getId()); return $response; @@ -272,7 +273,7 @@ class BuildController extends Controller $this->buildService->deleteBuild($build); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'project/view/' . $build->getProjectId()); return $response; diff --git a/src/PHPCensor/Controller/BuildStatusController.php b/src/PHPCensor/Controller/BuildStatusController.php index 36ab3a73..f6c6901a 100644 --- a/src/PHPCensor/Controller/BuildStatusController.php +++ b/src/PHPCensor/Controller/BuildStatusController.php @@ -2,8 +2,8 @@ namespace PHPCensor\Controller; -use b8\Http\Response; -use b8\Http\Response\RedirectResponse; +use PHPCensor\Http\Response; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Store\Factory; use PHPCensor\BuildFactory; diff --git a/src/PHPCensor/Controller/GroupController.php b/src/PHPCensor/Controller/GroupController.php index 5cb04c76..6d6011bb 100644 --- a/src/PHPCensor/Controller/GroupController.php +++ b/src/PHPCensor/Controller/GroupController.php @@ -5,6 +5,7 @@ namespace PHPCensor\Controller; use b8; use b8\Form; use PHPCensor\Controller; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\ProjectGroup; use PHPCensor\Helper\Lang; use PHPCensor\Model\User; @@ -58,8 +59,10 @@ class GroupController extends Controller /** * Add or edit a project group. + * * @param null $groupId - * @return void|b8\Http\Response\RedirectResponse + * + * @return RedirectResponse */ public function edit($groupId = null) { @@ -83,7 +86,7 @@ class GroupController extends Controller $this->groupStore->save($group); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'group'); return $response; @@ -112,7 +115,7 @@ class GroupController extends Controller /** * Delete a project group. * @param $groupId - * @return b8\Http\Response\RedirectResponse + * @return RedirectResponse */ public function delete($groupId) { @@ -120,7 +123,7 @@ class GroupController extends Controller $group = $this->groupStore->getById($groupId); $this->groupStore->delete($group); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'group'); return $response; } diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index 5db12a36..5904a52d 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -13,7 +13,7 @@ use PHPCensor\Helper\SshKey; use PHPCensor\Service\BuildService; use PHPCensor\Service\ProjectService; use PHPCensor\Model\Build; -use b8\Http\Response\RedirectResponse; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\View; use PHPCensor\Store\Factory; @@ -58,7 +58,7 @@ class ProjectController extends PHPCensor\Controller /** * @param int $projectId * - * @return b8\Http\Response + * @return PHPCensor\Http\Response */ public function ajaxBuilds($projectId) { @@ -581,7 +581,7 @@ class ProjectController extends PHPCensor\Controller { $github = new Github(); - $response = new b8\Http\Response\JsonResponse(); + $response = new PHPCensor\Http\Response\JsonResponse(); $response->setContent($github->getRepositories()); return $response; diff --git a/src/PHPCensor/Controller/SessionController.php b/src/PHPCensor/Controller/SessionController.php index d61d357e..60975e1e 100644 --- a/src/PHPCensor/Controller/SessionController.php +++ b/src/PHPCensor/Controller/SessionController.php @@ -6,6 +6,7 @@ use b8; use PHPCensor\Helper\Email; use PHPCensor\Helper\Lang; use PHPCensor\Controller; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Security\Authentication\Service; use PHPCensor\Store\UserStore; use PHPCensor\Store\Factory; @@ -48,7 +49,7 @@ class SessionController extends Controller if ($user) { $_SESSION['php-censor-user-id'] = $user->getId(); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', $this->getLoginRedirect()); return $response; @@ -108,7 +109,7 @@ class SessionController extends Controller ); } - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', $this->getLoginRedirect()); return $response; @@ -176,7 +177,7 @@ class SessionController extends Controller true ); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL); return $response; } @@ -237,7 +238,7 @@ class SessionController extends Controller $_SESSION['php-censor-user-id'] = $user->getId(); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL); return $response; } diff --git a/src/PHPCensor/Controller/UserController.php b/src/PHPCensor/Controller/UserController.php index c7df2325..4f264328 100644 --- a/src/PHPCensor/Controller/UserController.php +++ b/src/PHPCensor/Controller/UserController.php @@ -7,6 +7,7 @@ use PHPCensor\Exception\HttpException\NotFoundException; use b8\Form; use PHPCensor\Controller; use PHPCensor\Helper\Lang; +use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\User; use PHPCensor\Service\UserService; use PHPCensor\View; @@ -183,7 +184,7 @@ class UserController extends Controller $this->userService->createUser($name, $email, 'internal', json_encode(['type' => 'internal']), $password, $isAdmin); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL . 'user'); return $response; } @@ -224,7 +225,7 @@ class UserController extends Controller $this->userService->updateUser($user, $name, $email, $password, $isAdmin); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL . 'user'); return $response; } @@ -298,7 +299,7 @@ class UserController extends Controller $this->userService->deleteUser($user); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL . 'user'); return $response; } diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index c43e0635..3501e4e0 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -14,8 +14,8 @@ use PHPCensor\Controller; use PHPCensor\Config; use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Store\Factory; -use b8\Http\Request; -use b8\Http\Response; +use PHPCensor\Http\Request; +use PHPCensor\Http\Response; /** * Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc. @@ -70,7 +70,7 @@ class WebhookController extends Controller * @param string $action * @param mixed $actionParams * - * @return \b8\Http\Response + * @return Response */ public function handleAction($action, $actionParams) { diff --git a/src/PHPCensor/Controller/WidgetAllProjectsController.php b/src/PHPCensor/Controller/WidgetAllProjectsController.php index 4b1fb50b..0ddcac50 100644 --- a/src/PHPCensor/Controller/WidgetAllProjectsController.php +++ b/src/PHPCensor/Controller/WidgetAllProjectsController.php @@ -7,7 +7,7 @@ use PHPCensor\Controller; use PHPCensor\Store\Factory; use PHPCensor\View; use PHPCensor\Model\Project; -use b8\Http\Response; +use PHPCensor\Http\Response; use PHPCensor\Store\BuildStore; use PHPCensor\Store\ProjectStore; use PHPCensor\Store\ProjectGroupStore; diff --git a/src/PHPCensor/Controller/WidgetBuildErrorsController.php b/src/PHPCensor/Controller/WidgetBuildErrorsController.php index c80c2656..779500a9 100644 --- a/src/PHPCensor/Controller/WidgetBuildErrorsController.php +++ b/src/PHPCensor/Controller/WidgetBuildErrorsController.php @@ -4,7 +4,7 @@ namespace PHPCensor\Controller; use PHPCensor\Store\Factory; use PHPCensor\View; -use b8\Http\Response; +use PHPCensor\Http\Response; use PHPCensor\Controller; use PHPCensor\Store\BuildStore; use PHPCensor\Store\ProjectStore; diff --git a/src/PHPCensor/Controller/WidgetLastBuildsController.php b/src/PHPCensor/Controller/WidgetLastBuildsController.php index cb3ecd84..3f178018 100644 --- a/src/PHPCensor/Controller/WidgetLastBuildsController.php +++ b/src/PHPCensor/Controller/WidgetLastBuildsController.php @@ -4,7 +4,7 @@ namespace PHPCensor\Controller; use PHPCensor\Store\Factory; use PHPCensor\View; -use b8\Http\Response; +use PHPCensor\Http\Response; use PHPCensor\BuildFactory; use PHPCensor\Controller; use PHPCensor\Store\BuildStore; diff --git a/src/B8Framework/Http/Request.php b/src/PHPCensor/Http/Request.php similarity index 99% rename from src/B8Framework/Http/Request.php rename to src/PHPCensor/Http/Request.php index c5b9782a..69a3c04a 100644 --- a/src/B8Framework/Http/Request.php +++ b/src/PHPCensor/Http/Request.php @@ -1,6 +1,6 @@ prophesize('PHPCensor\Config')->reveal(), - $this->prophesize('b8\Http\Request')->reveal(), - $this->prophesize('b8\Http\Response')->reveal() + $this->prophesize('PHPCensor\Http\Request')->reveal(), + $this->prophesize('PHPCensor\Http\Response')->reveal() ); $error = $webController->handleAction('test', []); - self::assertInstanceOf('b8\Http\Response\JsonResponse', $error); + self::assertInstanceOf('PHPCensor\Http\Response\JsonResponse', $error); $responseData = $error->getData(); self::assertEquals(500, $responseData['code']); From cfe93434ad7c6b60abb75a8ffb1cf17d3cb733b3 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 17:50:08 +0700 Subject: [PATCH 11/28] Refactored Form. --- bootstrap.php | 1 - src/B8Framework/Form/Element/CheckboxGroup.php | 9 --------- src/B8Framework/Form/Element/Hidden.php | 9 --------- src/PHPCensor/Config.php | 4 ---- src/PHPCensor/Controller/GroupController.php | 3 +-- src/PHPCensor/Controller/ProjectController.php | 2 +- src/PHPCensor/Controller/SessionController.php | 15 +++++++-------- src/PHPCensor/Controller/UserController.php | 2 +- src/{B8Framework => PHPCensor}/Form.php | 5 ++--- .../Form/ControlGroup.php | 2 +- .../Form/Element.php | 7 +++---- .../Form/Element/Button.php | 4 ++-- .../Form/Element/Checkbox.php | 4 ++-- src/PHPCensor/Form/Element/CheckboxGroup.php | 9 +++++++++ .../Form/Element/Csrf.php | 2 +- .../Form/Element/Email.php | 2 +- src/PHPCensor/Form/Element/Hidden.php | 9 +++++++++ .../Form/Element/Password.php | 2 +- .../Form/Element/Radio.php | 2 +- .../Form/Element/Select.php | 4 ++-- .../Form/Element/Submit.php | 2 +- .../Form/Element/Text.php | 4 ++-- .../Form/Element/TextArea.php | 2 +- .../Form/Element/Url.php | 2 +- .../Form/FieldSet.php | 2 +- src/{B8Framework => PHPCensor}/Form/Input.php | 2 +- .../Form/View/Button.phtml | 0 .../Form/View/Checkbox.phtml | 4 ++-- .../Form/View/CheckboxGroup.phtml | 0 .../Form/View/ControlGroup.phtml | 0 .../Form/View/Csrf.phtml | 0 .../Form/View/FieldSet.phtml | 0 .../Form/View/Form.phtml | 0 .../Form/View/Hidden.phtml | 0 .../Form/View/Radio.phtml | 0 .../Form/View/Select.phtml | 0 .../Form/View/Text.phtml | 0 .../Form/View/TextArea.phtml | 0 src/PHPCensor/View.php | 2 +- tests/{B8Framework => PHPCensor}/FormTest.php | 18 ++---------------- tests/{B8Framework => PHPCensor}/ViewTest.php | 5 ++--- .../data/view/Form/form.phtml | 0 .../data/view/simple.phtml | 0 .../data/view/vars.phtml | 0 tests/bootstrap.php | 1 - 45 files changed, 58 insertions(+), 83 deletions(-) delete mode 100644 src/B8Framework/Form/Element/CheckboxGroup.php delete mode 100644 src/B8Framework/Form/Element/Hidden.php rename src/{B8Framework => PHPCensor}/Form.php (94%) rename src/{B8Framework => PHPCensor}/Form/ControlGroup.php (64%) rename src/{B8Framework => PHPCensor}/Form/Element.php (95%) rename src/{B8Framework => PHPCensor}/Form/Element/Button.php (84%) rename src/{B8Framework => PHPCensor}/Form/Element/Checkbox.php (95%) create mode 100644 src/PHPCensor/Form/Element/CheckboxGroup.php rename src/{B8Framework => PHPCensor}/Form/Element/Csrf.php (94%) rename src/{B8Framework => PHPCensor}/Form/Element/Email.php (92%) create mode 100644 src/PHPCensor/Form/Element/Hidden.php rename src/{B8Framework => PHPCensor}/Form/Element/Password.php (92%) rename src/{B8Framework => PHPCensor}/Form/Element/Radio.php (53%) rename src/{B8Framework => PHPCensor}/Form/Element/Select.php (88%) rename src/{B8Framework => PHPCensor}/Form/Element/Submit.php (93%) rename src/{B8Framework => PHPCensor}/Form/Element/Text.php (79%) rename src/{B8Framework => PHPCensor}/Form/Element/TextArea.php (93%) rename src/{B8Framework => PHPCensor}/Form/Element/Url.php (92%) rename src/{B8Framework => PHPCensor}/Form/FieldSet.php (98%) rename src/{B8Framework => PHPCensor}/Form/Input.php (99%) rename src/{B8Framework => PHPCensor}/Form/View/Button.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Checkbox.phtml (81%) rename src/{B8Framework => PHPCensor}/Form/View/CheckboxGroup.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/ControlGroup.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Csrf.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/FieldSet.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Form.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Hidden.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Radio.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Select.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/Text.phtml (100%) rename src/{B8Framework => PHPCensor}/Form/View/TextArea.phtml (100%) rename tests/{B8Framework => PHPCensor}/FormTest.php (94%) rename tests/{B8Framework => PHPCensor}/ViewTest.php (90%) rename tests/{B8Framework => PHPCensor}/data/view/Form/form.phtml (100%) rename tests/{B8Framework => PHPCensor}/data/view/simple.phtml (100%) rename tests/{B8Framework => PHPCensor}/data/view/vars.phtml (100%) diff --git a/bootstrap.php b/bootstrap.php index 7016a321..796c720b 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -30,7 +30,6 @@ require_once(ROOT_DIR . 'vendor/autoload.php'); $conf = []; $conf['b8']['app']['namespace'] = 'PHPCensor'; $conf['b8']['app']['default_controller'] = 'Home'; -$conf['b8']['view']['path'] = SRC_DIR . 'View/'; $config = new PHPCensor\Config($conf); diff --git a/src/B8Framework/Form/Element/CheckboxGroup.php b/src/B8Framework/Form/Element/CheckboxGroup.php deleted file mode 100644 index 0b8b7165..00000000 --- a/src/B8Framework/Form/Element/CheckboxGroup.php +++ /dev/null @@ -1,9 +0,0 @@ -setMethod('POST'); $form->setAction(APP_URL . 'session/login'); - $email = new b8\Form\Element\Text('email'); + $email = new \PHPCensor\Form\Element\Text('email'); $email->setLabel(Lang::get('login')); $email->setRequired(true); $email->setContainerClass('form-group'); $email->setClass('form-control'); $form->addField($email); - $pwd = new b8\Form\Element\Password('password'); + $pwd = new \PHPCensor\Form\Element\Password('password'); $pwd->setLabel(Lang::get('password')); $pwd->setRequired(true); $pwd->setContainerClass('form-group'); $pwd->setClass('form-control'); $form->addField($pwd); - $remember = b8\Form\Element\Checkbox::create('remember_me', Lang::get('remember_me'), false); + $remember = \PHPCensor\Form\Element\Checkbox::create('remember_me', Lang::get('remember_me'), false); $remember->setContainerClass('form-group'); $remember->setCheckedValue(1); $remember->setValue(0); $form->addField($remember); - $pwd = new b8\Form\Element\Submit(); + $pwd = new \PHPCensor\Form\Element\Submit(); $pwd->setValue(Lang::get('log_in')); $pwd->setClass('btn-success'); $form->addField($pwd); $tokenValue = $this->generateToken(); $_SESSION['login_token'] = $tokenValue; - $token = new b8\Form\Element\Hidden('token'); + $token = new \PHPCensor\Form\Element\Hidden('token'); $token->setValue($tokenValue); $form->addField($token); - $this->view->form = $form->render(); + $this->view->form = $form->render(); $this->view->failed = $isLoginFailure; return $this->view->render(); diff --git a/src/PHPCensor/Controller/UserController.php b/src/PHPCensor/Controller/UserController.php index 4f264328..3e8b5ab4 100644 --- a/src/PHPCensor/Controller/UserController.php +++ b/src/PHPCensor/Controller/UserController.php @@ -4,7 +4,7 @@ namespace PHPCensor\Controller; use PHPCensor\Config; use PHPCensor\Exception\HttpException\NotFoundException; -use b8\Form; +use PHPCensor\Form; use PHPCensor\Controller; use PHPCensor\Helper\Lang; use PHPCensor\Http\Response\RedirectResponse; diff --git a/src/B8Framework/Form.php b/src/PHPCensor/Form.php similarity index 94% rename from src/B8Framework/Form.php rename to src/PHPCensor/Form.php index 31ee1563..18b4c092 100644 --- a/src/B8Framework/Form.php +++ b/src/PHPCensor/Form.php @@ -1,9 +1,8 @@ get('b8.view.path'); + $viewPath = SRC_DIR . 'View/'; if (is_null($viewFile)) { $class = explode('\\', get_called_class()); @@ -178,7 +177,7 @@ abstract class Element if (file_exists($viewPath . 'Form/' . $viewFile . '.phtml')) { $view = new View('Form/' . $viewFile); } else { - $view = new View($viewFile, B8_PATH . 'Form/View/'); + $view = new View($viewFile, SRC_DIR . 'Form/View/'); } $view->name = $this->getName(); diff --git a/src/B8Framework/Form/Element/Button.php b/src/PHPCensor/Form/Element/Button.php similarity index 84% rename from src/B8Framework/Form/Element/Button.php rename to src/PHPCensor/Form/Element/Button.php index b3c7774b..80d9e3f5 100644 --- a/src/B8Framework/Form/Element/Button.php +++ b/src/PHPCensor/Form/Element/Button.php @@ -1,8 +1,8 @@ +
@@ -13,7 +13,7 @@ - +
diff --git a/src/B8Framework/Form/View/CheckboxGroup.phtml b/src/PHPCensor/Form/View/CheckboxGroup.phtml similarity index 100% rename from src/B8Framework/Form/View/CheckboxGroup.phtml rename to src/PHPCensor/Form/View/CheckboxGroup.phtml diff --git a/src/B8Framework/Form/View/ControlGroup.phtml b/src/PHPCensor/Form/View/ControlGroup.phtml similarity index 100% rename from src/B8Framework/Form/View/ControlGroup.phtml rename to src/PHPCensor/Form/View/ControlGroup.phtml diff --git a/src/B8Framework/Form/View/Csrf.phtml b/src/PHPCensor/Form/View/Csrf.phtml similarity index 100% rename from src/B8Framework/Form/View/Csrf.phtml rename to src/PHPCensor/Form/View/Csrf.phtml diff --git a/src/B8Framework/Form/View/FieldSet.phtml b/src/PHPCensor/Form/View/FieldSet.phtml similarity index 100% rename from src/B8Framework/Form/View/FieldSet.phtml rename to src/PHPCensor/Form/View/FieldSet.phtml diff --git a/src/B8Framework/Form/View/Form.phtml b/src/PHPCensor/Form/View/Form.phtml similarity index 100% rename from src/B8Framework/Form/View/Form.phtml rename to src/PHPCensor/Form/View/Form.phtml diff --git a/src/B8Framework/Form/View/Hidden.phtml b/src/PHPCensor/Form/View/Hidden.phtml similarity index 100% rename from src/B8Framework/Form/View/Hidden.phtml rename to src/PHPCensor/Form/View/Hidden.phtml diff --git a/src/B8Framework/Form/View/Radio.phtml b/src/PHPCensor/Form/View/Radio.phtml similarity index 100% rename from src/B8Framework/Form/View/Radio.phtml rename to src/PHPCensor/Form/View/Radio.phtml diff --git a/src/B8Framework/Form/View/Select.phtml b/src/PHPCensor/Form/View/Select.phtml similarity index 100% rename from src/B8Framework/Form/View/Select.phtml rename to src/PHPCensor/Form/View/Select.phtml diff --git a/src/B8Framework/Form/View/Text.phtml b/src/PHPCensor/Form/View/Text.phtml similarity index 100% rename from src/B8Framework/Form/View/Text.phtml rename to src/PHPCensor/Form/View/Text.phtml diff --git a/src/B8Framework/Form/View/TextArea.phtml b/src/PHPCensor/Form/View/TextArea.phtml similarity index 100% rename from src/B8Framework/Form/View/TextArea.phtml rename to src/PHPCensor/Form/View/TextArea.phtml diff --git a/src/PHPCensor/View.php b/src/PHPCensor/View.php index 1e06d1ac..1948b80d 100644 --- a/src/PHPCensor/View.php +++ b/src/PHPCensor/View.php @@ -28,7 +28,7 @@ class View protected static function getViewFile($file, $path = null) { - $viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path; + $viewPath = is_null($path) ? (SRC_DIR . 'View/') : $path; $fullPath = $viewPath . $file . '.' . static::$extension; return $fullPath; diff --git a/tests/B8Framework/FormTest.php b/tests/PHPCensor/FormTest.php similarity index 94% rename from tests/B8Framework/FormTest.php rename to tests/PHPCensor/FormTest.php index 9b59e465..01e5f288 100755 --- a/tests/B8Framework/FormTest.php +++ b/tests/PHPCensor/FormTest.php @@ -1,8 +1,8 @@ getAction() == '/'); self::assertTrue($f->getMethod() == 'POST'); - - new Config([ - 'b8' => [ - 'view' => [ - 'path' => __DIR__ . '/data/view/' - ] - ] - ]); - - self::assertTrue($f->render('form') == '/POST'); - - Config::getInstance()->set('b8.view.path', ''); - - self::assertTrue(strpos((string)$f, ' Date: Sun, 4 Mar 2018 18:04:15 +0700 Subject: [PATCH 12/28] Refactored project structure. --- .codecov.yml | 4 ++-- bootstrap.php | 2 +- composer.json | 6 ++---- phpunit.xml | 10 +++------- src/{PHPCensor => }/Application.php | 0 src/{PHPCensor => }/BuildFactory.php | 0 src/{PHPCensor => }/Builder.php | 0 src/{PHPCensor => }/BuilderException.php | 0 .../Command/CreateAdminCommand.php | 0 .../Command/CreateBuildCommand.php | 0 src/{PHPCensor => }/Command/InstallCommand.php | 0 src/{PHPCensor => }/Command/RebuildCommand.php | 0 .../Command/RebuildQueueCommand.php | 0 src/{PHPCensor => }/Command/RunCommand.php | 0 .../Command/ScheduleBuildCommand.php | 0 src/{PHPCensor => }/Command/WorkerCommand.php | 0 src/{PHPCensor => }/Config.php | 0 src/{PHPCensor => }/Console/Application.php | 2 +- src/{PHPCensor => }/Controller.php | 0 .../Controller/BuildController.php | 0 .../Controller/BuildStatusController.php | 0 .../Controller/GroupController.php | 0 .../Controller/HomeController.php | 0 .../Controller/ProjectController.php | 0 .../Controller/SessionController.php | 0 .../Controller/UserController.php | 0 .../Controller/WebhookController.php | 0 .../Controller/WidgetAllProjectsController.php | 0 .../Controller/WidgetBuildErrorsController.php | 0 .../Controller/WidgetLastBuildsController.php | 0 src/{PHPCensor => }/Database.php | 0 src/{PHPCensor => }/Exception/HttpException.php | 0 .../HttpException/BadRequestException.php | 0 .../HttpException/ForbiddenException.php | 0 .../HttpException/NotAuthorizedException.php | 0 .../HttpException/NotFoundException.php | 0 .../HttpException/ServerErrorException.php | 0 .../HttpException/ValidationException.php | 0 src/{PHPCensor => }/Form.php | 0 src/{PHPCensor => }/Form/ControlGroup.php | 0 src/{PHPCensor => }/Form/Element.php | 8 +------- src/{PHPCensor => }/Form/Element/Button.php | 0 src/{PHPCensor => }/Form/Element/Checkbox.php | 0 .../Form/Element/CheckboxGroup.php | 0 src/{PHPCensor => }/Form/Element/Csrf.php | 0 src/{PHPCensor => }/Form/Element/Email.php | 0 src/{PHPCensor => }/Form/Element/Hidden.php | 0 src/{PHPCensor => }/Form/Element/Password.php | 0 src/{PHPCensor => }/Form/Element/Radio.php | 0 src/{PHPCensor => }/Form/Element/Select.php | 0 src/{PHPCensor => }/Form/Element/Submit.php | 0 src/{PHPCensor => }/Form/Element/Text.php | 0 src/{PHPCensor => }/Form/Element/TextArea.php | 0 src/{PHPCensor => }/Form/Element/Url.php | 0 src/{PHPCensor => }/Form/FieldSet.php | 0 src/{PHPCensor => }/Form/Input.php | 0 src/{PHPCensor => }/Helper/AnsiConverter.php | 0 src/{PHPCensor => }/Helper/Bitbucket.php | 0 src/{PHPCensor => }/Helper/Build.php | 0 src/{PHPCensor => }/Helper/BuildInterpolator.php | 0 src/{PHPCensor => }/Helper/CommandExecutor.php | 0 .../Helper/CommandExecutorInterface.php | 0 src/{PHPCensor => }/Helper/Diff.php | 0 src/{PHPCensor => }/Helper/Email.php | 0 src/{PHPCensor => }/Helper/Github.php | 0 src/{PHPCensor => }/Helper/Lang.php | 0 src/{PHPCensor => }/Helper/MailerFactory.php | 0 src/{PHPCensor => }/Helper/SshKey.php | 0 src/{PHPCensor => }/Http/Request.php | 0 src/{PHPCensor => }/Http/Response.php | 0 .../Http/Response/JsonResponse.php | 0 .../Http/Response/RedirectResponse.php | 0 src/{PHPCensor => }/Http/Router.php | 0 src/{PHPCensor => }/Languages/lang.da.php | 0 src/{PHPCensor => }/Languages/lang.de.php | 0 src/{PHPCensor => }/Languages/lang.el.php | 0 src/{PHPCensor => }/Languages/lang.en.php | 0 src/{PHPCensor => }/Languages/lang.es.php | 0 src/{PHPCensor => }/Languages/lang.fr.php | 0 src/{PHPCensor => }/Languages/lang.it.php | 0 src/{PHPCensor => }/Languages/lang.nl.php | 0 src/{PHPCensor => }/Languages/lang.pl.php | 0 src/{PHPCensor => }/Languages/lang.pt-br.php | 0 src/{PHPCensor => }/Languages/lang.ru.php | 0 src/{PHPCensor => }/Languages/lang.uk.php | 0 src/{PHPCensor => }/Languages/lang.zh.php | 0 .../Logging/BuildDBLogHandler.php | 0 src/{PHPCensor => }/Logging/BuildLogger.php | 0 src/{PHPCensor => }/Logging/Handler.php | 0 .../Logging/LoggedBuildContextTidier.php | 0 src/{PHPCensor => }/Logging/OutputLogHandler.php | 0 .../20140513143726_initial_migration.php | 0 ...0140513153133_change_build_keys_migration.php | 0 .../Migrations/20140611170618_choose_branch.php | 0 .../20140730143702_fix_database_columns.php | 0 .../20150131075425_archive_project.php | 0 .../20150203105015_fix_column_types.php | 0 .../20150308074509_add_user_providers.php | 0 ...4174958_unique_email_and_name_user_fields.php | 0 .../20151008140800_add_project_groups.php | 0 .../20151009100610_remove_unique_name_index.php | 0 .../Migrations/20151014091859_errors_table.php | 0 .../Migrations/20151015124825_convert_errors.php | 0 .../20160425162114_branch_column_length.php | 0 .../20160623100223_project_table_defaults.php | 0 ...3312_added_language_and_per_page_for_user.php | 0 ...18175400_fixed_build_error_message_column.php | 0 ...23113127_fixed_build_log_column_for_mysql.php | 0 ...6132922_fixed_build_log_column_for_mysql2.php | 0 .../20170321131931_add_environment.php | 0 ...131256_added_source_column_to_build_table.php | 0 .../20170416130610_fixed_environments.php | 0 ...420142131_added_tag_column_to_build_table.php | 0 ...20170711112805_fixed_build_meta_for_mysql.php | 0 .../20170828142020_added_remember_me_login.php | 0 .../20170913141438_added_default_branch_only.php | 0 ...173348_removed_project_id_from_build_meta.php | 0 .../20171015123827_added_additional_columns.php | 0 .../20171016143000_added_additional_columns2.php | 0 .../20171019143346_added_additional_columns3.php | 0 ...20171209135004_added_new_label_for_errors.php | 0 ...80223052715_added_request_branch_to_build.php | 0 .../20180228024622_renamed_build_types.php | 0 src/{PHPCensor => }/Model.php | 0 src/{PHPCensor => }/Model/Build.php | 0 .../Model/Build/BitbucketBuild.php | 0 .../Model/Build/BitbucketHgBuild.php | 0 src/{PHPCensor => }/Model/Build/GitBuild.php | 0 src/{PHPCensor => }/Model/Build/GithubBuild.php | 0 src/{PHPCensor => }/Model/Build/GitlabBuild.php | 0 src/{PHPCensor => }/Model/Build/GogsBuild.php | 0 src/{PHPCensor => }/Model/Build/HgBuild.php | 0 src/{PHPCensor => }/Model/Build/LocalBuild.php | 0 src/{PHPCensor => }/Model/Build/SvnBuild.php | 0 src/{PHPCensor => }/Model/BuildError.php | 0 src/{PHPCensor => }/Model/BuildMeta.php | 0 src/{PHPCensor => }/Model/Environment.php | 0 src/{PHPCensor => }/Model/Project.php | 0 src/{PHPCensor => }/Model/ProjectGroup.php | 0 src/{PHPCensor => }/Model/User.php | 0 src/{PHPCensor => }/Plugin.php | 0 src/{PHPCensor => }/Plugin/Atoum.php | 0 src/{PHPCensor => }/Plugin/Behat.php | 0 src/{PHPCensor => }/Plugin/Campfire.php | 0 src/{PHPCensor => }/Plugin/CleanBuild.php | 0 src/{PHPCensor => }/Plugin/Codeception.php | 0 src/{PHPCensor => }/Plugin/Composer.php | 0 src/{PHPCensor => }/Plugin/CopyBuild.php | 0 src/{PHPCensor => }/Plugin/Deployer.php | 0 src/{PHPCensor => }/Plugin/Email.php | 0 src/{PHPCensor => }/Plugin/Env.php | 0 src/{PHPCensor => }/Plugin/FlowdockNotify.php | 0 src/{PHPCensor => }/Plugin/Git.php | 0 src/{PHPCensor => }/Plugin/Grunt.php | 0 src/{PHPCensor => }/Plugin/Gulp.php | 0 src/{PHPCensor => }/Plugin/HipchatNotify.php | 0 src/{PHPCensor => }/Plugin/Irc.php | 0 src/{PHPCensor => }/Plugin/Lint.php | 0 src/{PHPCensor => }/Plugin/Mage.php | 0 src/{PHPCensor => }/Plugin/Mage3.php | 0 src/{PHPCensor => }/Plugin/Mysql.php | 0 .../Plugin/Option/PhpUnitOptions.php | 0 src/{PHPCensor => }/Plugin/PackageBuild.php | 0 src/{PHPCensor => }/Plugin/Pdepend.php | 0 src/{PHPCensor => }/Plugin/Pgsql.php | 0 src/{PHPCensor => }/Plugin/Phar.php | 0 src/{PHPCensor => }/Plugin/Phing.php | 0 src/{PHPCensor => }/Plugin/PhpCodeSniffer.php | 0 src/{PHPCensor => }/Plugin/PhpCpd.php | 0 src/{PHPCensor => }/Plugin/PhpCsFixer.php | 0 .../Plugin/PhpDocblockChecker.php | 0 src/{PHPCensor => }/Plugin/PhpLoc.php | 0 src/{PHPCensor => }/Plugin/PhpMessDetector.php | 0 src/{PHPCensor => }/Plugin/PhpParallelLint.php | 0 src/{PHPCensor => }/Plugin/PhpSpec.php | 0 src/{PHPCensor => }/Plugin/PhpTalLint.php | 4 ++-- src/{PHPCensor => }/Plugin/PhpUnit.php | 0 src/{PHPCensor => }/Plugin/SecurityChecker.php | 0 src/{PHPCensor => }/Plugin/Shell.php | 0 src/{PHPCensor => }/Plugin/SlackNotify.php | 0 src/{PHPCensor => }/Plugin/Sqlite.php | 0 src/{PHPCensor => }/Plugin/TechnicalDebt.php | 0 src/{PHPCensor => }/Plugin/Util/Executor.php | 0 src/{PHPCensor => }/Plugin/Util/Factory.php | 0 .../Plugin/Util/PhpUnitResult.php | 0 .../Plugin/Util/PhpUnitResultJson.php | 0 .../Plugin/Util/PhpUnitResultJunit.php | 0 .../Util/TestResultParsers/Codeception.php | 0 .../Util/TestResultParsers/ParserInterface.php | 0 src/{PHPCensor => }/Plugin/Wipe.php | 0 src/{PHPCensor => }/Plugin/Xmpp.php | 0 src/{PHPCensor => }/ProcessControl/Factory.php | 0 .../ProcessControl/PosixProcessControl.php | 0 .../ProcessControl/ProcessControlInterface.php | 0 .../ProcessControl/UnixProcessControl.php | 0 .../LoginPasswordProviderInterface.php | 0 .../Security/Authentication/Service.php | 0 .../UserProvider/AbstractProvider.php | 0 .../Authentication/UserProvider/Internal.php | 0 .../Authentication/UserProvider/Ldap.php | 0 .../Authentication/UserProviderInterface.php | 0 src/{PHPCensor => }/Service/BuildService.php | 0 .../Service/BuildStatusService.php | 0 src/{PHPCensor => }/Service/ProjectService.php | 0 src/{PHPCensor => }/Service/UserService.php | 0 src/{PHPCensor => }/Store.php | 0 src/{PHPCensor => }/Store/BuildErrorStore.php | 0 src/{PHPCensor => }/Store/BuildErrorWriter.php | 0 src/{PHPCensor => }/Store/BuildMetaStore.php | 0 src/{PHPCensor => }/Store/BuildStore.php | 0 src/{PHPCensor => }/Store/EnvironmentStore.php | 0 src/{PHPCensor => }/Store/Factory.php | 0 src/{PHPCensor => }/Store/ProjectGroupStore.php | 0 src/{PHPCensor => }/Store/ProjectStore.php | 0 src/{PHPCensor => }/Store/UserStore.php | 0 src/{PHPCensor => }/View.php | 0 src/{PHPCensor => }/View/Build/errors.phtml | 0 src/{PHPCensor => }/View/Build/header-row.phtml | 0 src/{PHPCensor => }/View/Build/view.phtml | 0 src/{PHPCensor => }/View/BuildStatus/view.phtml | 0 src/{PHPCensor => }/View/Email/layout.phtml | 2 +- src/{PHPCensor => }/View/Email/long.phtml | 0 src/{PHPCensor => }/View/Email/short.phtml | 0 .../Form/View => View/Form}/Button.phtml | 0 .../Form/View => View/Form}/Checkbox.phtml | 0 .../Form/View => View/Form}/CheckboxGroup.phtml | 0 .../Form/View => View/Form}/ControlGroup.phtml | 0 .../Form/View => View/Form}/Csrf.phtml | 0 .../Form/View => View/Form}/FieldSet.phtml | 0 .../Form/View => View/Form}/Form.phtml | 0 .../Form/View => View/Form}/Hidden.phtml | 0 .../Form/View => View/Form}/Radio.phtml | 0 .../Form/View => View/Form}/Select.phtml | 0 .../Form/View => View/Form}/Text.phtml | 0 .../Form/View => View/Form}/TextArea.phtml | 0 src/{PHPCensor => }/View/Group/edit.phtml | 0 src/{PHPCensor => }/View/Group/index.phtml | 0 src/{PHPCensor => }/View/Home/index.phtml | 0 .../View/Project/ajax-builds.phtml | 0 src/{PHPCensor => }/View/Project/edit.phtml | 0 src/{PHPCensor => }/View/Project/view.phtml | 0 src/{PHPCensor => }/View/Session.phtml | 0 .../View/Session/forgotPassword.phtml | 0 src/{PHPCensor => }/View/Session/login.phtml | 0 .../View/Session/resetPassword.phtml | 0 src/{PHPCensor => }/View/User/edit.phtml | 0 src/{PHPCensor => }/View/User/index.phtml | 0 src/{PHPCensor => }/View/User/profile.phtml | 0 .../View/WidgetAllProjects/index-projects.phtml | 0 .../View/WidgetAllProjects/index.phtml | 0 .../View/WidgetAllProjects/update.phtml | 0 .../View/WidgetBuildErrors/empty.phtml | 0 .../View/WidgetBuildErrors/index.phtml | 0 .../View/WidgetBuildErrors/update.phtml | 0 .../View/WidgetLastBuilds/index.phtml | 0 .../View/WidgetLastBuilds/update.phtml | 0 src/{PHPCensor => }/View/exception.phtml | 0 src/{PHPCensor => }/View/layout.phtml | 0 src/{PHPCensor => }/View/pagination.phtml | 0 src/{PHPCensor => }/Worker/BuildWorker.php | 0 .../ZeroConfigPluginInterface.php | 0 tests/bootstrap.php | 2 +- .../Plugin/PhpUnit}/invalid_format.txt | 0 .../Plugin/PhpUnit}/phpunit_money.txt | 0 .../Plugin/PhpUnit}/phpunit_money_junit.xml | 0 .../data/view => data/View}/Form/form.phtml | 0 .../data/view => data/View}/simple.phtml | 0 .../data/view => data/View}/vars.phtml | 0 tests/{temp => runtime}/.gitkeep | 0 .../Command/CreateAdminCommandTest.php | 2 +- .../Command/CreateBuildCommandTest.php | 0 .../Command/InstallCommandTest.php | 2 +- .../Controller/WebhookControllerTest.php | 0 tests/{PHPCensor => src}/DatabaseMysqlTest.php | 0 .../DatabasePostgresqlTest.php | 0 tests/{PHPCensor => src}/FormTest.php | 1 - .../Helper/AnsiConverterTest.php | 0 .../Helper/BuildInterpolatorTest.php | 2 +- .../Helper/CommandExecutorTest.php | 0 .../Helper/MailerFactoryTest.php | 2 +- tests/{PHPCensor => src}/HttpExceptionTest.php | 0 .../Logging/BuildLoggerTest.php | 2 +- tests/{PHPCensor => src}/Model/BuildTest.php | 0 tests/{PHPCensor => src}/Model/ProjectTest.php | 0 tests/{PHPCensor => src}/Plugin/EmailTest.php | 0 .../Plugin/Option/PhpUnitOptionsTest.php | 2 +- tests/{PHPCensor => src}/Plugin/PharTest.php | 2 +- tests/{PHPCensor => src}/Plugin/PhpUnitTest.php | 0 .../Plugin/Util/ExecutorTest.php | 16 +++++++++------- .../Plugin/Util/FactoryTest.php | 0 .../Plugin/Util/Fake/ExamplePluginFull.php | 0 .../Fake/ExamplePluginWithNoConstructorArgs.php | 0 .../Fake/ExamplePluginWithSingleOptionalArg.php | 0 .../Fake/ExamplePluginWithSingleRequiredArg.php | 0 .../ExamplePluginWithSingleTypedRequiredArg.php | 0 .../Plugin/Util/PhpUnitResultTest.php | 4 ++-- .../ProcessControl/PosixProcessControlTest.php | 1 + .../ProcessControl/ProcessControlTest.php | 1 + .../ProcessControl/UnixProcessControlTest.php | 1 + .../Security/Authentication/ServiceTest.php | 0 .../Authentication/UserProvider/InternalTest.php | 0 .../Service/BuildServiceTest.php | 0 .../Service/BuiltStatusServiceTest.php | 2 +- .../Service/ProjectServiceTest.php | 0 .../Service/UserServiceTest.php | 0 tests/{PHPCensor => src}/StoreMysqlTest.php | 0 tests/{PHPCensor => src}/StorePostgresqlTest.php | 0 tests/{PHPCensor => src}/ViewTest.php | 6 +++--- 308 files changed, 39 insertions(+), 47 deletions(-) rename src/{PHPCensor => }/Application.php (100%) rename src/{PHPCensor => }/BuildFactory.php (100%) rename src/{PHPCensor => }/Builder.php (100%) rename src/{PHPCensor => }/BuilderException.php (100%) rename src/{PHPCensor => }/Command/CreateAdminCommand.php (100%) rename src/{PHPCensor => }/Command/CreateBuildCommand.php (100%) rename src/{PHPCensor => }/Command/InstallCommand.php (100%) rename src/{PHPCensor => }/Command/RebuildCommand.php (100%) rename src/{PHPCensor => }/Command/RebuildQueueCommand.php (100%) rename src/{PHPCensor => }/Command/RunCommand.php (100%) rename src/{PHPCensor => }/Command/ScheduleBuildCommand.php (100%) rename src/{PHPCensor => }/Command/WorkerCommand.php (100%) rename src/{PHPCensor => }/Config.php (100%) rename src/{PHPCensor => }/Console/Application.php (98%) rename src/{PHPCensor => }/Controller.php (100%) rename src/{PHPCensor => }/Controller/BuildController.php (100%) rename src/{PHPCensor => }/Controller/BuildStatusController.php (100%) rename src/{PHPCensor => }/Controller/GroupController.php (100%) rename src/{PHPCensor => }/Controller/HomeController.php (100%) rename src/{PHPCensor => }/Controller/ProjectController.php (100%) rename src/{PHPCensor => }/Controller/SessionController.php (100%) rename src/{PHPCensor => }/Controller/UserController.php (100%) rename src/{PHPCensor => }/Controller/WebhookController.php (100%) rename src/{PHPCensor => }/Controller/WidgetAllProjectsController.php (100%) rename src/{PHPCensor => }/Controller/WidgetBuildErrorsController.php (100%) rename src/{PHPCensor => }/Controller/WidgetLastBuildsController.php (100%) rename src/{PHPCensor => }/Database.php (100%) rename src/{PHPCensor => }/Exception/HttpException.php (100%) rename src/{PHPCensor => }/Exception/HttpException/BadRequestException.php (100%) rename src/{PHPCensor => }/Exception/HttpException/ForbiddenException.php (100%) rename src/{PHPCensor => }/Exception/HttpException/NotAuthorizedException.php (100%) rename src/{PHPCensor => }/Exception/HttpException/NotFoundException.php (100%) rename src/{PHPCensor => }/Exception/HttpException/ServerErrorException.php (100%) rename src/{PHPCensor => }/Exception/HttpException/ValidationException.php (100%) rename src/{PHPCensor => }/Form.php (100%) rename src/{PHPCensor => }/Form/ControlGroup.php (100%) rename src/{PHPCensor => }/Form/Element.php (92%) rename src/{PHPCensor => }/Form/Element/Button.php (100%) rename src/{PHPCensor => }/Form/Element/Checkbox.php (100%) rename src/{PHPCensor => }/Form/Element/CheckboxGroup.php (100%) rename src/{PHPCensor => }/Form/Element/Csrf.php (100%) rename src/{PHPCensor => }/Form/Element/Email.php (100%) rename src/{PHPCensor => }/Form/Element/Hidden.php (100%) rename src/{PHPCensor => }/Form/Element/Password.php (100%) rename src/{PHPCensor => }/Form/Element/Radio.php (100%) rename src/{PHPCensor => }/Form/Element/Select.php (100%) rename src/{PHPCensor => }/Form/Element/Submit.php (100%) rename src/{PHPCensor => }/Form/Element/Text.php (100%) rename src/{PHPCensor => }/Form/Element/TextArea.php (100%) rename src/{PHPCensor => }/Form/Element/Url.php (100%) rename src/{PHPCensor => }/Form/FieldSet.php (100%) rename src/{PHPCensor => }/Form/Input.php (100%) rename src/{PHPCensor => }/Helper/AnsiConverter.php (100%) rename src/{PHPCensor => }/Helper/Bitbucket.php (100%) rename src/{PHPCensor => }/Helper/Build.php (100%) rename src/{PHPCensor => }/Helper/BuildInterpolator.php (100%) rename src/{PHPCensor => }/Helper/CommandExecutor.php (100%) rename src/{PHPCensor => }/Helper/CommandExecutorInterface.php (100%) rename src/{PHPCensor => }/Helper/Diff.php (100%) rename src/{PHPCensor => }/Helper/Email.php (100%) rename src/{PHPCensor => }/Helper/Github.php (100%) rename src/{PHPCensor => }/Helper/Lang.php (100%) rename src/{PHPCensor => }/Helper/MailerFactory.php (100%) rename src/{PHPCensor => }/Helper/SshKey.php (100%) rename src/{PHPCensor => }/Http/Request.php (100%) rename src/{PHPCensor => }/Http/Response.php (100%) rename src/{PHPCensor => }/Http/Response/JsonResponse.php (100%) rename src/{PHPCensor => }/Http/Response/RedirectResponse.php (100%) rename src/{PHPCensor => }/Http/Router.php (100%) rename src/{PHPCensor => }/Languages/lang.da.php (100%) rename src/{PHPCensor => }/Languages/lang.de.php (100%) rename src/{PHPCensor => }/Languages/lang.el.php (100%) rename src/{PHPCensor => }/Languages/lang.en.php (100%) rename src/{PHPCensor => }/Languages/lang.es.php (100%) rename src/{PHPCensor => }/Languages/lang.fr.php (100%) rename src/{PHPCensor => }/Languages/lang.it.php (100%) rename src/{PHPCensor => }/Languages/lang.nl.php (100%) rename src/{PHPCensor => }/Languages/lang.pl.php (100%) rename src/{PHPCensor => }/Languages/lang.pt-br.php (100%) rename src/{PHPCensor => }/Languages/lang.ru.php (100%) rename src/{PHPCensor => }/Languages/lang.uk.php (100%) rename src/{PHPCensor => }/Languages/lang.zh.php (100%) rename src/{PHPCensor => }/Logging/BuildDBLogHandler.php (100%) rename src/{PHPCensor => }/Logging/BuildLogger.php (100%) rename src/{PHPCensor => }/Logging/Handler.php (100%) rename src/{PHPCensor => }/Logging/LoggedBuildContextTidier.php (100%) rename src/{PHPCensor => }/Logging/OutputLogHandler.php (100%) rename src/{PHPCensor => }/Migrations/20140513143726_initial_migration.php (100%) rename src/{PHPCensor => }/Migrations/20140513153133_change_build_keys_migration.php (100%) rename src/{PHPCensor => }/Migrations/20140611170618_choose_branch.php (100%) rename src/{PHPCensor => }/Migrations/20140730143702_fix_database_columns.php (100%) rename src/{PHPCensor => }/Migrations/20150131075425_archive_project.php (100%) rename src/{PHPCensor => }/Migrations/20150203105015_fix_column_types.php (100%) rename src/{PHPCensor => }/Migrations/20150308074509_add_user_providers.php (100%) rename src/{PHPCensor => }/Migrations/20150324174958_unique_email_and_name_user_fields.php (100%) rename src/{PHPCensor => }/Migrations/20151008140800_add_project_groups.php (100%) rename src/{PHPCensor => }/Migrations/20151009100610_remove_unique_name_index.php (100%) rename src/{PHPCensor => }/Migrations/20151014091859_errors_table.php (100%) rename src/{PHPCensor => }/Migrations/20151015124825_convert_errors.php (100%) rename src/{PHPCensor => }/Migrations/20160425162114_branch_column_length.php (100%) rename src/{PHPCensor => }/Migrations/20160623100223_project_table_defaults.php (100%) rename src/{PHPCensor => }/Migrations/20170103163312_added_language_and_per_page_for_user.php (100%) rename src/{PHPCensor => }/Migrations/20170218175400_fixed_build_error_message_column.php (100%) rename src/{PHPCensor => }/Migrations/20170223113127_fixed_build_log_column_for_mysql.php (100%) rename src/{PHPCensor => }/Migrations/20170226132922_fixed_build_log_column_for_mysql2.php (100%) rename src/{PHPCensor => }/Migrations/20170321131931_add_environment.php (100%) rename src/{PHPCensor => }/Migrations/20170413131256_added_source_column_to_build_table.php (100%) rename src/{PHPCensor => }/Migrations/20170416130610_fixed_environments.php (100%) rename src/{PHPCensor => }/Migrations/20170420142131_added_tag_column_to_build_table.php (100%) rename src/{PHPCensor => }/Migrations/20170711112805_fixed_build_meta_for_mysql.php (100%) rename src/{PHPCensor => }/Migrations/20170828142020_added_remember_me_login.php (100%) rename src/{PHPCensor => }/Migrations/20170913141438_added_default_branch_only.php (100%) rename src/{PHPCensor => }/Migrations/20171014173348_removed_project_id_from_build_meta.php (100%) rename src/{PHPCensor => }/Migrations/20171015123827_added_additional_columns.php (100%) rename src/{PHPCensor => }/Migrations/20171016143000_added_additional_columns2.php (100%) rename src/{PHPCensor => }/Migrations/20171019143346_added_additional_columns3.php (100%) rename src/{PHPCensor => }/Migrations/20171209135004_added_new_label_for_errors.php (100%) rename src/{PHPCensor => }/Migrations/20180223052715_added_request_branch_to_build.php (100%) rename src/{PHPCensor => }/Migrations/20180228024622_renamed_build_types.php (100%) rename src/{PHPCensor => }/Model.php (100%) rename src/{PHPCensor => }/Model/Build.php (100%) rename src/{PHPCensor => }/Model/Build/BitbucketBuild.php (100%) rename src/{PHPCensor => }/Model/Build/BitbucketHgBuild.php (100%) rename src/{PHPCensor => }/Model/Build/GitBuild.php (100%) rename src/{PHPCensor => }/Model/Build/GithubBuild.php (100%) rename src/{PHPCensor => }/Model/Build/GitlabBuild.php (100%) rename src/{PHPCensor => }/Model/Build/GogsBuild.php (100%) rename src/{PHPCensor => }/Model/Build/HgBuild.php (100%) rename src/{PHPCensor => }/Model/Build/LocalBuild.php (100%) rename src/{PHPCensor => }/Model/Build/SvnBuild.php (100%) rename src/{PHPCensor => }/Model/BuildError.php (100%) rename src/{PHPCensor => }/Model/BuildMeta.php (100%) rename src/{PHPCensor => }/Model/Environment.php (100%) rename src/{PHPCensor => }/Model/Project.php (100%) rename src/{PHPCensor => }/Model/ProjectGroup.php (100%) rename src/{PHPCensor => }/Model/User.php (100%) rename src/{PHPCensor => }/Plugin.php (100%) rename src/{PHPCensor => }/Plugin/Atoum.php (100%) rename src/{PHPCensor => }/Plugin/Behat.php (100%) rename src/{PHPCensor => }/Plugin/Campfire.php (100%) rename src/{PHPCensor => }/Plugin/CleanBuild.php (100%) rename src/{PHPCensor => }/Plugin/Codeception.php (100%) rename src/{PHPCensor => }/Plugin/Composer.php (100%) rename src/{PHPCensor => }/Plugin/CopyBuild.php (100%) rename src/{PHPCensor => }/Plugin/Deployer.php (100%) rename src/{PHPCensor => }/Plugin/Email.php (100%) rename src/{PHPCensor => }/Plugin/Env.php (100%) rename src/{PHPCensor => }/Plugin/FlowdockNotify.php (100%) rename src/{PHPCensor => }/Plugin/Git.php (100%) rename src/{PHPCensor => }/Plugin/Grunt.php (100%) rename src/{PHPCensor => }/Plugin/Gulp.php (100%) rename src/{PHPCensor => }/Plugin/HipchatNotify.php (100%) rename src/{PHPCensor => }/Plugin/Irc.php (100%) rename src/{PHPCensor => }/Plugin/Lint.php (100%) rename src/{PHPCensor => }/Plugin/Mage.php (100%) rename src/{PHPCensor => }/Plugin/Mage3.php (100%) rename src/{PHPCensor => }/Plugin/Mysql.php (100%) rename src/{PHPCensor => }/Plugin/Option/PhpUnitOptions.php (100%) rename src/{PHPCensor => }/Plugin/PackageBuild.php (100%) rename src/{PHPCensor => }/Plugin/Pdepend.php (100%) rename src/{PHPCensor => }/Plugin/Pgsql.php (100%) rename src/{PHPCensor => }/Plugin/Phar.php (100%) rename src/{PHPCensor => }/Plugin/Phing.php (100%) rename src/{PHPCensor => }/Plugin/PhpCodeSniffer.php (100%) rename src/{PHPCensor => }/Plugin/PhpCpd.php (100%) rename src/{PHPCensor => }/Plugin/PhpCsFixer.php (100%) rename src/{PHPCensor => }/Plugin/PhpDocblockChecker.php (100%) rename src/{PHPCensor => }/Plugin/PhpLoc.php (100%) rename src/{PHPCensor => }/Plugin/PhpMessDetector.php (100%) rename src/{PHPCensor => }/Plugin/PhpParallelLint.php (100%) rename src/{PHPCensor => }/Plugin/PhpSpec.php (100%) rename src/{PHPCensor => }/Plugin/PhpTalLint.php (98%) rename src/{PHPCensor => }/Plugin/PhpUnit.php (100%) rename src/{PHPCensor => }/Plugin/SecurityChecker.php (100%) rename src/{PHPCensor => }/Plugin/Shell.php (100%) rename src/{PHPCensor => }/Plugin/SlackNotify.php (100%) rename src/{PHPCensor => }/Plugin/Sqlite.php (100%) rename src/{PHPCensor => }/Plugin/TechnicalDebt.php (100%) rename src/{PHPCensor => }/Plugin/Util/Executor.php (100%) rename src/{PHPCensor => }/Plugin/Util/Factory.php (100%) rename src/{PHPCensor => }/Plugin/Util/PhpUnitResult.php (100%) rename src/{PHPCensor => }/Plugin/Util/PhpUnitResultJson.php (100%) rename src/{PHPCensor => }/Plugin/Util/PhpUnitResultJunit.php (100%) rename src/{PHPCensor => }/Plugin/Util/TestResultParsers/Codeception.php (100%) rename src/{PHPCensor => }/Plugin/Util/TestResultParsers/ParserInterface.php (100%) rename src/{PHPCensor => }/Plugin/Wipe.php (100%) rename src/{PHPCensor => }/Plugin/Xmpp.php (100%) rename src/{PHPCensor => }/ProcessControl/Factory.php (100%) rename src/{PHPCensor => }/ProcessControl/PosixProcessControl.php (100%) rename src/{PHPCensor => }/ProcessControl/ProcessControlInterface.php (100%) rename src/{PHPCensor => }/ProcessControl/UnixProcessControl.php (100%) rename src/{PHPCensor => }/Security/Authentication/LoginPasswordProviderInterface.php (100%) rename src/{PHPCensor => }/Security/Authentication/Service.php (100%) rename src/{PHPCensor => }/Security/Authentication/UserProvider/AbstractProvider.php (100%) rename src/{PHPCensor => }/Security/Authentication/UserProvider/Internal.php (100%) rename src/{PHPCensor => }/Security/Authentication/UserProvider/Ldap.php (100%) rename src/{PHPCensor => }/Security/Authentication/UserProviderInterface.php (100%) rename src/{PHPCensor => }/Service/BuildService.php (100%) rename src/{PHPCensor => }/Service/BuildStatusService.php (100%) rename src/{PHPCensor => }/Service/ProjectService.php (100%) rename src/{PHPCensor => }/Service/UserService.php (100%) rename src/{PHPCensor => }/Store.php (100%) rename src/{PHPCensor => }/Store/BuildErrorStore.php (100%) rename src/{PHPCensor => }/Store/BuildErrorWriter.php (100%) rename src/{PHPCensor => }/Store/BuildMetaStore.php (100%) rename src/{PHPCensor => }/Store/BuildStore.php (100%) rename src/{PHPCensor => }/Store/EnvironmentStore.php (100%) rename src/{PHPCensor => }/Store/Factory.php (100%) rename src/{PHPCensor => }/Store/ProjectGroupStore.php (100%) rename src/{PHPCensor => }/Store/ProjectStore.php (100%) rename src/{PHPCensor => }/Store/UserStore.php (100%) rename src/{PHPCensor => }/View.php (100%) rename src/{PHPCensor => }/View/Build/errors.phtml (100%) rename src/{PHPCensor => }/View/Build/header-row.phtml (100%) rename src/{PHPCensor => }/View/Build/view.phtml (100%) rename src/{PHPCensor => }/View/BuildStatus/view.phtml (100%) rename src/{PHPCensor => }/View/Email/layout.phtml (93%) rename src/{PHPCensor => }/View/Email/long.phtml (100%) rename src/{PHPCensor => }/View/Email/short.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Button.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Checkbox.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/CheckboxGroup.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/ControlGroup.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Csrf.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/FieldSet.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Form.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Hidden.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Radio.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Select.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/Text.phtml (100%) rename src/{PHPCensor/Form/View => View/Form}/TextArea.phtml (100%) rename src/{PHPCensor => }/View/Group/edit.phtml (100%) rename src/{PHPCensor => }/View/Group/index.phtml (100%) rename src/{PHPCensor => }/View/Home/index.phtml (100%) rename src/{PHPCensor => }/View/Project/ajax-builds.phtml (100%) rename src/{PHPCensor => }/View/Project/edit.phtml (100%) rename src/{PHPCensor => }/View/Project/view.phtml (100%) rename src/{PHPCensor => }/View/Session.phtml (100%) rename src/{PHPCensor => }/View/Session/forgotPassword.phtml (100%) rename src/{PHPCensor => }/View/Session/login.phtml (100%) rename src/{PHPCensor => }/View/Session/resetPassword.phtml (100%) rename src/{PHPCensor => }/View/User/edit.phtml (100%) rename src/{PHPCensor => }/View/User/index.phtml (100%) rename src/{PHPCensor => }/View/User/profile.phtml (100%) rename src/{PHPCensor => }/View/WidgetAllProjects/index-projects.phtml (100%) rename src/{PHPCensor => }/View/WidgetAllProjects/index.phtml (100%) rename src/{PHPCensor => }/View/WidgetAllProjects/update.phtml (100%) rename src/{PHPCensor => }/View/WidgetBuildErrors/empty.phtml (100%) rename src/{PHPCensor => }/View/WidgetBuildErrors/index.phtml (100%) rename src/{PHPCensor => }/View/WidgetBuildErrors/update.phtml (100%) rename src/{PHPCensor => }/View/WidgetLastBuilds/index.phtml (100%) rename src/{PHPCensor => }/View/WidgetLastBuilds/update.phtml (100%) rename src/{PHPCensor => }/View/exception.phtml (100%) rename src/{PHPCensor => }/View/layout.phtml (100%) rename src/{PHPCensor => }/View/pagination.phtml (100%) rename src/{PHPCensor => }/Worker/BuildWorker.php (100%) rename src/{PHPCensor => }/ZeroConfigPluginInterface.php (100%) rename tests/{PHPCensor/Plugin/SampleFiles => data/Plugin/PhpUnit}/invalid_format.txt (100%) rename tests/{PHPCensor/Plugin/SampleFiles => data/Plugin/PhpUnit}/phpunit_money.txt (100%) rename tests/{PHPCensor/Plugin/SampleFiles => data/Plugin/PhpUnit}/phpunit_money_junit.xml (100%) rename tests/{PHPCensor/data/view => data/View}/Form/form.phtml (100%) rename tests/{PHPCensor/data/view => data/View}/simple.phtml (100%) rename tests/{PHPCensor/data/view => data/View}/vars.phtml (100%) rename tests/{temp => runtime}/.gitkeep (100%) rename tests/{PHPCensor => src}/Command/CreateAdminCommandTest.php (97%) rename tests/{PHPCensor => src}/Command/CreateBuildCommandTest.php (100%) rename tests/{PHPCensor => src}/Command/InstallCommandTest.php (99%) rename tests/{PHPCensor => src}/Controller/WebhookControllerTest.php (100%) rename tests/{PHPCensor => src}/DatabaseMysqlTest.php (100%) rename tests/{PHPCensor => src}/DatabasePostgresqlTest.php (100%) rename tests/{PHPCensor => src}/FormTest.php (99%) rename tests/{PHPCensor => src}/Helper/AnsiConverterTest.php (100%) rename tests/{PHPCensor => src}/Helper/BuildInterpolatorTest.php (96%) rename tests/{PHPCensor => src}/Helper/CommandExecutorTest.php (100%) rename tests/{PHPCensor => src}/Helper/MailerFactoryTest.php (98%) rename tests/{PHPCensor => src}/HttpExceptionTest.php (100%) rename tests/{PHPCensor => src}/Logging/BuildLoggerTest.php (98%) rename tests/{PHPCensor => src}/Model/BuildTest.php (100%) rename tests/{PHPCensor => src}/Model/ProjectTest.php (100%) rename tests/{PHPCensor => src}/Plugin/EmailTest.php (100%) rename tests/{PHPCensor => src}/Plugin/Option/PhpUnitOptionsTest.php (98%) rename tests/{PHPCensor => src}/Plugin/PharTest.php (98%) rename tests/{PHPCensor => src}/Plugin/PhpUnitTest.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/ExecutorTest.php (93%) rename tests/{PHPCensor => src}/Plugin/Util/FactoryTest.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/Fake/ExamplePluginFull.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/Fake/ExamplePluginWithNoConstructorArgs.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/Fake/ExamplePluginWithSingleOptionalArg.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/Fake/ExamplePluginWithSingleRequiredArg.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/Fake/ExamplePluginWithSingleTypedRequiredArg.php (100%) rename tests/{PHPCensor => src}/Plugin/Util/PhpUnitResultTest.php (93%) rename tests/{PHPCensor => src}/ProcessControl/PosixProcessControlTest.php (99%) rename tests/{PHPCensor => src}/ProcessControl/ProcessControlTest.php (99%) rename tests/{PHPCensor => src}/ProcessControl/UnixProcessControlTest.php (99%) rename tests/{PHPCensor => src}/Security/Authentication/ServiceTest.php (100%) rename tests/{PHPCensor => src}/Security/Authentication/UserProvider/InternalTest.php (100%) rename tests/{PHPCensor => src}/Service/BuildServiceTest.php (100%) rename tests/{PHPCensor => src}/Service/BuiltStatusServiceTest.php (99%) rename tests/{PHPCensor => src}/Service/ProjectServiceTest.php (100%) rename tests/{PHPCensor => src}/Service/UserServiceTest.php (100%) rename tests/{PHPCensor => src}/StoreMysqlTest.php (100%) rename tests/{PHPCensor => src}/StorePostgresqlTest.php (100%) rename tests/{PHPCensor => src}/ViewTest.php (79%) diff --git a/.codecov.yml b/.codecov.yml index 2d4e363c..f98f123f 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -6,7 +6,7 @@ coverage: - "runtime" - "tests" - "vendor" - - "src/PHPCensor/Migrations" - - "src/PHPCensor/Languages" + - "src/Migrations" + - "src/Languages" comment: off diff --git a/bootstrap.php b/bootstrap.php index 796c720b..2bb67d62 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,7 +5,7 @@ if (!defined('ROOT_DIR')) { } if (!defined('SRC_DIR')) { - define('SRC_DIR', ROOT_DIR . 'src/PHPCensor/'); + define('SRC_DIR', ROOT_DIR . 'src/'); } if (!defined('PUBLIC_DIR')) { diff --git a/composer.json b/composer.json index 111af7df..90e36e05 100644 --- a/composer.json +++ b/composer.json @@ -36,14 +36,12 @@ }, "autoload": { "psr-4": { - "PHPCensor\\": "src/PHPCensor/", - "b8\\": "src/B8Framework/" + "PHPCensor\\": "src/" } }, "autoload-dev": { "psr-4": { - "Tests\\PHPCensor\\": "tests/PHPCensor/", - "Tests\\b8\\": "tests/B8Framework/" + "Tests\\PHPCensor\\": "tests/src/" } }, "require": { diff --git a/phpunit.xml b/phpunit.xml index 703620a2..2974b6b8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,20 +20,16 @@ - - ./tests/B8Framework - - - ./tests/PHPCensor + ./tests/src ./src - ./src/PHPCensor/Migrations - ./src/PHPCensor/Languages + ./src/Migrations + ./src/Languages diff --git a/src/PHPCensor/Application.php b/src/Application.php similarity index 100% rename from src/PHPCensor/Application.php rename to src/Application.php diff --git a/src/PHPCensor/BuildFactory.php b/src/BuildFactory.php similarity index 100% rename from src/PHPCensor/BuildFactory.php rename to src/BuildFactory.php diff --git a/src/PHPCensor/Builder.php b/src/Builder.php similarity index 100% rename from src/PHPCensor/Builder.php rename to src/Builder.php diff --git a/src/PHPCensor/BuilderException.php b/src/BuilderException.php similarity index 100% rename from src/PHPCensor/BuilderException.php rename to src/BuilderException.php diff --git a/src/PHPCensor/Command/CreateAdminCommand.php b/src/Command/CreateAdminCommand.php similarity index 100% rename from src/PHPCensor/Command/CreateAdminCommand.php rename to src/Command/CreateAdminCommand.php diff --git a/src/PHPCensor/Command/CreateBuildCommand.php b/src/Command/CreateBuildCommand.php similarity index 100% rename from src/PHPCensor/Command/CreateBuildCommand.php rename to src/Command/CreateBuildCommand.php diff --git a/src/PHPCensor/Command/InstallCommand.php b/src/Command/InstallCommand.php similarity index 100% rename from src/PHPCensor/Command/InstallCommand.php rename to src/Command/InstallCommand.php diff --git a/src/PHPCensor/Command/RebuildCommand.php b/src/Command/RebuildCommand.php similarity index 100% rename from src/PHPCensor/Command/RebuildCommand.php rename to src/Command/RebuildCommand.php diff --git a/src/PHPCensor/Command/RebuildQueueCommand.php b/src/Command/RebuildQueueCommand.php similarity index 100% rename from src/PHPCensor/Command/RebuildQueueCommand.php rename to src/Command/RebuildQueueCommand.php diff --git a/src/PHPCensor/Command/RunCommand.php b/src/Command/RunCommand.php similarity index 100% rename from src/PHPCensor/Command/RunCommand.php rename to src/Command/RunCommand.php diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/Command/ScheduleBuildCommand.php similarity index 100% rename from src/PHPCensor/Command/ScheduleBuildCommand.php rename to src/Command/ScheduleBuildCommand.php diff --git a/src/PHPCensor/Command/WorkerCommand.php b/src/Command/WorkerCommand.php similarity index 100% rename from src/PHPCensor/Command/WorkerCommand.php rename to src/Command/WorkerCommand.php diff --git a/src/PHPCensor/Config.php b/src/Config.php similarity index 100% rename from src/PHPCensor/Config.php rename to src/Config.php diff --git a/src/PHPCensor/Console/Application.php b/src/Console/Application.php similarity index 98% rename from src/PHPCensor/Console/Application.php rename to src/Console/Application.php index d65031b9..470603ac 100644 --- a/src/PHPCensor/Console/Application.php +++ b/src/Console/Application.php @@ -86,7 +86,7 @@ LOGO; if ($databaseSettings) { $phinxSettings = [ 'paths' => [ - 'migrations' => ROOT_DIR . 'src/PHPCensor/Migrations', + 'migrations' => ROOT_DIR . 'src/Migrations', ], 'environments' => [ 'default_migration_table' => 'migration', diff --git a/src/PHPCensor/Controller.php b/src/Controller.php similarity index 100% rename from src/PHPCensor/Controller.php rename to src/Controller.php diff --git a/src/PHPCensor/Controller/BuildController.php b/src/Controller/BuildController.php similarity index 100% rename from src/PHPCensor/Controller/BuildController.php rename to src/Controller/BuildController.php diff --git a/src/PHPCensor/Controller/BuildStatusController.php b/src/Controller/BuildStatusController.php similarity index 100% rename from src/PHPCensor/Controller/BuildStatusController.php rename to src/Controller/BuildStatusController.php diff --git a/src/PHPCensor/Controller/GroupController.php b/src/Controller/GroupController.php similarity index 100% rename from src/PHPCensor/Controller/GroupController.php rename to src/Controller/GroupController.php diff --git a/src/PHPCensor/Controller/HomeController.php b/src/Controller/HomeController.php similarity index 100% rename from src/PHPCensor/Controller/HomeController.php rename to src/Controller/HomeController.php diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/Controller/ProjectController.php similarity index 100% rename from src/PHPCensor/Controller/ProjectController.php rename to src/Controller/ProjectController.php diff --git a/src/PHPCensor/Controller/SessionController.php b/src/Controller/SessionController.php similarity index 100% rename from src/PHPCensor/Controller/SessionController.php rename to src/Controller/SessionController.php diff --git a/src/PHPCensor/Controller/UserController.php b/src/Controller/UserController.php similarity index 100% rename from src/PHPCensor/Controller/UserController.php rename to src/Controller/UserController.php diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/Controller/WebhookController.php similarity index 100% rename from src/PHPCensor/Controller/WebhookController.php rename to src/Controller/WebhookController.php diff --git a/src/PHPCensor/Controller/WidgetAllProjectsController.php b/src/Controller/WidgetAllProjectsController.php similarity index 100% rename from src/PHPCensor/Controller/WidgetAllProjectsController.php rename to src/Controller/WidgetAllProjectsController.php diff --git a/src/PHPCensor/Controller/WidgetBuildErrorsController.php b/src/Controller/WidgetBuildErrorsController.php similarity index 100% rename from src/PHPCensor/Controller/WidgetBuildErrorsController.php rename to src/Controller/WidgetBuildErrorsController.php diff --git a/src/PHPCensor/Controller/WidgetLastBuildsController.php b/src/Controller/WidgetLastBuildsController.php similarity index 100% rename from src/PHPCensor/Controller/WidgetLastBuildsController.php rename to src/Controller/WidgetLastBuildsController.php diff --git a/src/PHPCensor/Database.php b/src/Database.php similarity index 100% rename from src/PHPCensor/Database.php rename to src/Database.php diff --git a/src/PHPCensor/Exception/HttpException.php b/src/Exception/HttpException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException.php rename to src/Exception/HttpException.php diff --git a/src/PHPCensor/Exception/HttpException/BadRequestException.php b/src/Exception/HttpException/BadRequestException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException/BadRequestException.php rename to src/Exception/HttpException/BadRequestException.php diff --git a/src/PHPCensor/Exception/HttpException/ForbiddenException.php b/src/Exception/HttpException/ForbiddenException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException/ForbiddenException.php rename to src/Exception/HttpException/ForbiddenException.php diff --git a/src/PHPCensor/Exception/HttpException/NotAuthorizedException.php b/src/Exception/HttpException/NotAuthorizedException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException/NotAuthorizedException.php rename to src/Exception/HttpException/NotAuthorizedException.php diff --git a/src/PHPCensor/Exception/HttpException/NotFoundException.php b/src/Exception/HttpException/NotFoundException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException/NotFoundException.php rename to src/Exception/HttpException/NotFoundException.php diff --git a/src/PHPCensor/Exception/HttpException/ServerErrorException.php b/src/Exception/HttpException/ServerErrorException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException/ServerErrorException.php rename to src/Exception/HttpException/ServerErrorException.php diff --git a/src/PHPCensor/Exception/HttpException/ValidationException.php b/src/Exception/HttpException/ValidationException.php similarity index 100% rename from src/PHPCensor/Exception/HttpException/ValidationException.php rename to src/Exception/HttpException/ValidationException.php diff --git a/src/PHPCensor/Form.php b/src/Form.php similarity index 100% rename from src/PHPCensor/Form.php rename to src/Form.php diff --git a/src/PHPCensor/Form/ControlGroup.php b/src/Form/ControlGroup.php similarity index 100% rename from src/PHPCensor/Form/ControlGroup.php rename to src/Form/ControlGroup.php diff --git a/src/PHPCensor/Form/Element.php b/src/Form/Element.php similarity index 92% rename from src/PHPCensor/Form/Element.php rename to src/Form/Element.php index dc9b742a..038260ad 100644 --- a/src/PHPCensor/Form/Element.php +++ b/src/Form/Element.php @@ -167,18 +167,12 @@ abstract class Element */ public function render($viewFile = null) { - $viewPath = SRC_DIR . 'View/'; - if (is_null($viewFile)) { $class = explode('\\', get_called_class()); $viewFile = end($class); } - if (file_exists($viewPath . 'Form/' . $viewFile . '.phtml')) { - $view = new View('Form/' . $viewFile); - } else { - $view = new View($viewFile, SRC_DIR . 'Form/View/'); - } + $view = new View('Form/' . $viewFile); $view->name = $this->getName(); $view->id = $this->getId(); diff --git a/src/PHPCensor/Form/Element/Button.php b/src/Form/Element/Button.php similarity index 100% rename from src/PHPCensor/Form/Element/Button.php rename to src/Form/Element/Button.php diff --git a/src/PHPCensor/Form/Element/Checkbox.php b/src/Form/Element/Checkbox.php similarity index 100% rename from src/PHPCensor/Form/Element/Checkbox.php rename to src/Form/Element/Checkbox.php diff --git a/src/PHPCensor/Form/Element/CheckboxGroup.php b/src/Form/Element/CheckboxGroup.php similarity index 100% rename from src/PHPCensor/Form/Element/CheckboxGroup.php rename to src/Form/Element/CheckboxGroup.php diff --git a/src/PHPCensor/Form/Element/Csrf.php b/src/Form/Element/Csrf.php similarity index 100% rename from src/PHPCensor/Form/Element/Csrf.php rename to src/Form/Element/Csrf.php diff --git a/src/PHPCensor/Form/Element/Email.php b/src/Form/Element/Email.php similarity index 100% rename from src/PHPCensor/Form/Element/Email.php rename to src/Form/Element/Email.php diff --git a/src/PHPCensor/Form/Element/Hidden.php b/src/Form/Element/Hidden.php similarity index 100% rename from src/PHPCensor/Form/Element/Hidden.php rename to src/Form/Element/Hidden.php diff --git a/src/PHPCensor/Form/Element/Password.php b/src/Form/Element/Password.php similarity index 100% rename from src/PHPCensor/Form/Element/Password.php rename to src/Form/Element/Password.php diff --git a/src/PHPCensor/Form/Element/Radio.php b/src/Form/Element/Radio.php similarity index 100% rename from src/PHPCensor/Form/Element/Radio.php rename to src/Form/Element/Radio.php diff --git a/src/PHPCensor/Form/Element/Select.php b/src/Form/Element/Select.php similarity index 100% rename from src/PHPCensor/Form/Element/Select.php rename to src/Form/Element/Select.php diff --git a/src/PHPCensor/Form/Element/Submit.php b/src/Form/Element/Submit.php similarity index 100% rename from src/PHPCensor/Form/Element/Submit.php rename to src/Form/Element/Submit.php diff --git a/src/PHPCensor/Form/Element/Text.php b/src/Form/Element/Text.php similarity index 100% rename from src/PHPCensor/Form/Element/Text.php rename to src/Form/Element/Text.php diff --git a/src/PHPCensor/Form/Element/TextArea.php b/src/Form/Element/TextArea.php similarity index 100% rename from src/PHPCensor/Form/Element/TextArea.php rename to src/Form/Element/TextArea.php diff --git a/src/PHPCensor/Form/Element/Url.php b/src/Form/Element/Url.php similarity index 100% rename from src/PHPCensor/Form/Element/Url.php rename to src/Form/Element/Url.php diff --git a/src/PHPCensor/Form/FieldSet.php b/src/Form/FieldSet.php similarity index 100% rename from src/PHPCensor/Form/FieldSet.php rename to src/Form/FieldSet.php diff --git a/src/PHPCensor/Form/Input.php b/src/Form/Input.php similarity index 100% rename from src/PHPCensor/Form/Input.php rename to src/Form/Input.php diff --git a/src/PHPCensor/Helper/AnsiConverter.php b/src/Helper/AnsiConverter.php similarity index 100% rename from src/PHPCensor/Helper/AnsiConverter.php rename to src/Helper/AnsiConverter.php diff --git a/src/PHPCensor/Helper/Bitbucket.php b/src/Helper/Bitbucket.php similarity index 100% rename from src/PHPCensor/Helper/Bitbucket.php rename to src/Helper/Bitbucket.php diff --git a/src/PHPCensor/Helper/Build.php b/src/Helper/Build.php similarity index 100% rename from src/PHPCensor/Helper/Build.php rename to src/Helper/Build.php diff --git a/src/PHPCensor/Helper/BuildInterpolator.php b/src/Helper/BuildInterpolator.php similarity index 100% rename from src/PHPCensor/Helper/BuildInterpolator.php rename to src/Helper/BuildInterpolator.php diff --git a/src/PHPCensor/Helper/CommandExecutor.php b/src/Helper/CommandExecutor.php similarity index 100% rename from src/PHPCensor/Helper/CommandExecutor.php rename to src/Helper/CommandExecutor.php diff --git a/src/PHPCensor/Helper/CommandExecutorInterface.php b/src/Helper/CommandExecutorInterface.php similarity index 100% rename from src/PHPCensor/Helper/CommandExecutorInterface.php rename to src/Helper/CommandExecutorInterface.php diff --git a/src/PHPCensor/Helper/Diff.php b/src/Helper/Diff.php similarity index 100% rename from src/PHPCensor/Helper/Diff.php rename to src/Helper/Diff.php diff --git a/src/PHPCensor/Helper/Email.php b/src/Helper/Email.php similarity index 100% rename from src/PHPCensor/Helper/Email.php rename to src/Helper/Email.php diff --git a/src/PHPCensor/Helper/Github.php b/src/Helper/Github.php similarity index 100% rename from src/PHPCensor/Helper/Github.php rename to src/Helper/Github.php diff --git a/src/PHPCensor/Helper/Lang.php b/src/Helper/Lang.php similarity index 100% rename from src/PHPCensor/Helper/Lang.php rename to src/Helper/Lang.php diff --git a/src/PHPCensor/Helper/MailerFactory.php b/src/Helper/MailerFactory.php similarity index 100% rename from src/PHPCensor/Helper/MailerFactory.php rename to src/Helper/MailerFactory.php diff --git a/src/PHPCensor/Helper/SshKey.php b/src/Helper/SshKey.php similarity index 100% rename from src/PHPCensor/Helper/SshKey.php rename to src/Helper/SshKey.php diff --git a/src/PHPCensor/Http/Request.php b/src/Http/Request.php similarity index 100% rename from src/PHPCensor/Http/Request.php rename to src/Http/Request.php diff --git a/src/PHPCensor/Http/Response.php b/src/Http/Response.php similarity index 100% rename from src/PHPCensor/Http/Response.php rename to src/Http/Response.php diff --git a/src/PHPCensor/Http/Response/JsonResponse.php b/src/Http/Response/JsonResponse.php similarity index 100% rename from src/PHPCensor/Http/Response/JsonResponse.php rename to src/Http/Response/JsonResponse.php diff --git a/src/PHPCensor/Http/Response/RedirectResponse.php b/src/Http/Response/RedirectResponse.php similarity index 100% rename from src/PHPCensor/Http/Response/RedirectResponse.php rename to src/Http/Response/RedirectResponse.php diff --git a/src/PHPCensor/Http/Router.php b/src/Http/Router.php similarity index 100% rename from src/PHPCensor/Http/Router.php rename to src/Http/Router.php diff --git a/src/PHPCensor/Languages/lang.da.php b/src/Languages/lang.da.php similarity index 100% rename from src/PHPCensor/Languages/lang.da.php rename to src/Languages/lang.da.php diff --git a/src/PHPCensor/Languages/lang.de.php b/src/Languages/lang.de.php similarity index 100% rename from src/PHPCensor/Languages/lang.de.php rename to src/Languages/lang.de.php diff --git a/src/PHPCensor/Languages/lang.el.php b/src/Languages/lang.el.php similarity index 100% rename from src/PHPCensor/Languages/lang.el.php rename to src/Languages/lang.el.php diff --git a/src/PHPCensor/Languages/lang.en.php b/src/Languages/lang.en.php similarity index 100% rename from src/PHPCensor/Languages/lang.en.php rename to src/Languages/lang.en.php diff --git a/src/PHPCensor/Languages/lang.es.php b/src/Languages/lang.es.php similarity index 100% rename from src/PHPCensor/Languages/lang.es.php rename to src/Languages/lang.es.php diff --git a/src/PHPCensor/Languages/lang.fr.php b/src/Languages/lang.fr.php similarity index 100% rename from src/PHPCensor/Languages/lang.fr.php rename to src/Languages/lang.fr.php diff --git a/src/PHPCensor/Languages/lang.it.php b/src/Languages/lang.it.php similarity index 100% rename from src/PHPCensor/Languages/lang.it.php rename to src/Languages/lang.it.php diff --git a/src/PHPCensor/Languages/lang.nl.php b/src/Languages/lang.nl.php similarity index 100% rename from src/PHPCensor/Languages/lang.nl.php rename to src/Languages/lang.nl.php diff --git a/src/PHPCensor/Languages/lang.pl.php b/src/Languages/lang.pl.php similarity index 100% rename from src/PHPCensor/Languages/lang.pl.php rename to src/Languages/lang.pl.php diff --git a/src/PHPCensor/Languages/lang.pt-br.php b/src/Languages/lang.pt-br.php similarity index 100% rename from src/PHPCensor/Languages/lang.pt-br.php rename to src/Languages/lang.pt-br.php diff --git a/src/PHPCensor/Languages/lang.ru.php b/src/Languages/lang.ru.php similarity index 100% rename from src/PHPCensor/Languages/lang.ru.php rename to src/Languages/lang.ru.php diff --git a/src/PHPCensor/Languages/lang.uk.php b/src/Languages/lang.uk.php similarity index 100% rename from src/PHPCensor/Languages/lang.uk.php rename to src/Languages/lang.uk.php diff --git a/src/PHPCensor/Languages/lang.zh.php b/src/Languages/lang.zh.php similarity index 100% rename from src/PHPCensor/Languages/lang.zh.php rename to src/Languages/lang.zh.php diff --git a/src/PHPCensor/Logging/BuildDBLogHandler.php b/src/Logging/BuildDBLogHandler.php similarity index 100% rename from src/PHPCensor/Logging/BuildDBLogHandler.php rename to src/Logging/BuildDBLogHandler.php diff --git a/src/PHPCensor/Logging/BuildLogger.php b/src/Logging/BuildLogger.php similarity index 100% rename from src/PHPCensor/Logging/BuildLogger.php rename to src/Logging/BuildLogger.php diff --git a/src/PHPCensor/Logging/Handler.php b/src/Logging/Handler.php similarity index 100% rename from src/PHPCensor/Logging/Handler.php rename to src/Logging/Handler.php diff --git a/src/PHPCensor/Logging/LoggedBuildContextTidier.php b/src/Logging/LoggedBuildContextTidier.php similarity index 100% rename from src/PHPCensor/Logging/LoggedBuildContextTidier.php rename to src/Logging/LoggedBuildContextTidier.php diff --git a/src/PHPCensor/Logging/OutputLogHandler.php b/src/Logging/OutputLogHandler.php similarity index 100% rename from src/PHPCensor/Logging/OutputLogHandler.php rename to src/Logging/OutputLogHandler.php diff --git a/src/PHPCensor/Migrations/20140513143726_initial_migration.php b/src/Migrations/20140513143726_initial_migration.php similarity index 100% rename from src/PHPCensor/Migrations/20140513143726_initial_migration.php rename to src/Migrations/20140513143726_initial_migration.php diff --git a/src/PHPCensor/Migrations/20140513153133_change_build_keys_migration.php b/src/Migrations/20140513153133_change_build_keys_migration.php similarity index 100% rename from src/PHPCensor/Migrations/20140513153133_change_build_keys_migration.php rename to src/Migrations/20140513153133_change_build_keys_migration.php diff --git a/src/PHPCensor/Migrations/20140611170618_choose_branch.php b/src/Migrations/20140611170618_choose_branch.php similarity index 100% rename from src/PHPCensor/Migrations/20140611170618_choose_branch.php rename to src/Migrations/20140611170618_choose_branch.php diff --git a/src/PHPCensor/Migrations/20140730143702_fix_database_columns.php b/src/Migrations/20140730143702_fix_database_columns.php similarity index 100% rename from src/PHPCensor/Migrations/20140730143702_fix_database_columns.php rename to src/Migrations/20140730143702_fix_database_columns.php diff --git a/src/PHPCensor/Migrations/20150131075425_archive_project.php b/src/Migrations/20150131075425_archive_project.php similarity index 100% rename from src/PHPCensor/Migrations/20150131075425_archive_project.php rename to src/Migrations/20150131075425_archive_project.php diff --git a/src/PHPCensor/Migrations/20150203105015_fix_column_types.php b/src/Migrations/20150203105015_fix_column_types.php similarity index 100% rename from src/PHPCensor/Migrations/20150203105015_fix_column_types.php rename to src/Migrations/20150203105015_fix_column_types.php diff --git a/src/PHPCensor/Migrations/20150308074509_add_user_providers.php b/src/Migrations/20150308074509_add_user_providers.php similarity index 100% rename from src/PHPCensor/Migrations/20150308074509_add_user_providers.php rename to src/Migrations/20150308074509_add_user_providers.php diff --git a/src/PHPCensor/Migrations/20150324174958_unique_email_and_name_user_fields.php b/src/Migrations/20150324174958_unique_email_and_name_user_fields.php similarity index 100% rename from src/PHPCensor/Migrations/20150324174958_unique_email_and_name_user_fields.php rename to src/Migrations/20150324174958_unique_email_and_name_user_fields.php diff --git a/src/PHPCensor/Migrations/20151008140800_add_project_groups.php b/src/Migrations/20151008140800_add_project_groups.php similarity index 100% rename from src/PHPCensor/Migrations/20151008140800_add_project_groups.php rename to src/Migrations/20151008140800_add_project_groups.php diff --git a/src/PHPCensor/Migrations/20151009100610_remove_unique_name_index.php b/src/Migrations/20151009100610_remove_unique_name_index.php similarity index 100% rename from src/PHPCensor/Migrations/20151009100610_remove_unique_name_index.php rename to src/Migrations/20151009100610_remove_unique_name_index.php diff --git a/src/PHPCensor/Migrations/20151014091859_errors_table.php b/src/Migrations/20151014091859_errors_table.php similarity index 100% rename from src/PHPCensor/Migrations/20151014091859_errors_table.php rename to src/Migrations/20151014091859_errors_table.php diff --git a/src/PHPCensor/Migrations/20151015124825_convert_errors.php b/src/Migrations/20151015124825_convert_errors.php similarity index 100% rename from src/PHPCensor/Migrations/20151015124825_convert_errors.php rename to src/Migrations/20151015124825_convert_errors.php diff --git a/src/PHPCensor/Migrations/20160425162114_branch_column_length.php b/src/Migrations/20160425162114_branch_column_length.php similarity index 100% rename from src/PHPCensor/Migrations/20160425162114_branch_column_length.php rename to src/Migrations/20160425162114_branch_column_length.php diff --git a/src/PHPCensor/Migrations/20160623100223_project_table_defaults.php b/src/Migrations/20160623100223_project_table_defaults.php similarity index 100% rename from src/PHPCensor/Migrations/20160623100223_project_table_defaults.php rename to src/Migrations/20160623100223_project_table_defaults.php diff --git a/src/PHPCensor/Migrations/20170103163312_added_language_and_per_page_for_user.php b/src/Migrations/20170103163312_added_language_and_per_page_for_user.php similarity index 100% rename from src/PHPCensor/Migrations/20170103163312_added_language_and_per_page_for_user.php rename to src/Migrations/20170103163312_added_language_and_per_page_for_user.php diff --git a/src/PHPCensor/Migrations/20170218175400_fixed_build_error_message_column.php b/src/Migrations/20170218175400_fixed_build_error_message_column.php similarity index 100% rename from src/PHPCensor/Migrations/20170218175400_fixed_build_error_message_column.php rename to src/Migrations/20170218175400_fixed_build_error_message_column.php diff --git a/src/PHPCensor/Migrations/20170223113127_fixed_build_log_column_for_mysql.php b/src/Migrations/20170223113127_fixed_build_log_column_for_mysql.php similarity index 100% rename from src/PHPCensor/Migrations/20170223113127_fixed_build_log_column_for_mysql.php rename to src/Migrations/20170223113127_fixed_build_log_column_for_mysql.php diff --git a/src/PHPCensor/Migrations/20170226132922_fixed_build_log_column_for_mysql2.php b/src/Migrations/20170226132922_fixed_build_log_column_for_mysql2.php similarity index 100% rename from src/PHPCensor/Migrations/20170226132922_fixed_build_log_column_for_mysql2.php rename to src/Migrations/20170226132922_fixed_build_log_column_for_mysql2.php diff --git a/src/PHPCensor/Migrations/20170321131931_add_environment.php b/src/Migrations/20170321131931_add_environment.php similarity index 100% rename from src/PHPCensor/Migrations/20170321131931_add_environment.php rename to src/Migrations/20170321131931_add_environment.php diff --git a/src/PHPCensor/Migrations/20170413131256_added_source_column_to_build_table.php b/src/Migrations/20170413131256_added_source_column_to_build_table.php similarity index 100% rename from src/PHPCensor/Migrations/20170413131256_added_source_column_to_build_table.php rename to src/Migrations/20170413131256_added_source_column_to_build_table.php diff --git a/src/PHPCensor/Migrations/20170416130610_fixed_environments.php b/src/Migrations/20170416130610_fixed_environments.php similarity index 100% rename from src/PHPCensor/Migrations/20170416130610_fixed_environments.php rename to src/Migrations/20170416130610_fixed_environments.php diff --git a/src/PHPCensor/Migrations/20170420142131_added_tag_column_to_build_table.php b/src/Migrations/20170420142131_added_tag_column_to_build_table.php similarity index 100% rename from src/PHPCensor/Migrations/20170420142131_added_tag_column_to_build_table.php rename to src/Migrations/20170420142131_added_tag_column_to_build_table.php diff --git a/src/PHPCensor/Migrations/20170711112805_fixed_build_meta_for_mysql.php b/src/Migrations/20170711112805_fixed_build_meta_for_mysql.php similarity index 100% rename from src/PHPCensor/Migrations/20170711112805_fixed_build_meta_for_mysql.php rename to src/Migrations/20170711112805_fixed_build_meta_for_mysql.php diff --git a/src/PHPCensor/Migrations/20170828142020_added_remember_me_login.php b/src/Migrations/20170828142020_added_remember_me_login.php similarity index 100% rename from src/PHPCensor/Migrations/20170828142020_added_remember_me_login.php rename to src/Migrations/20170828142020_added_remember_me_login.php diff --git a/src/PHPCensor/Migrations/20170913141438_added_default_branch_only.php b/src/Migrations/20170913141438_added_default_branch_only.php similarity index 100% rename from src/PHPCensor/Migrations/20170913141438_added_default_branch_only.php rename to src/Migrations/20170913141438_added_default_branch_only.php diff --git a/src/PHPCensor/Migrations/20171014173348_removed_project_id_from_build_meta.php b/src/Migrations/20171014173348_removed_project_id_from_build_meta.php similarity index 100% rename from src/PHPCensor/Migrations/20171014173348_removed_project_id_from_build_meta.php rename to src/Migrations/20171014173348_removed_project_id_from_build_meta.php diff --git a/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php b/src/Migrations/20171015123827_added_additional_columns.php similarity index 100% rename from src/PHPCensor/Migrations/20171015123827_added_additional_columns.php rename to src/Migrations/20171015123827_added_additional_columns.php diff --git a/src/PHPCensor/Migrations/20171016143000_added_additional_columns2.php b/src/Migrations/20171016143000_added_additional_columns2.php similarity index 100% rename from src/PHPCensor/Migrations/20171016143000_added_additional_columns2.php rename to src/Migrations/20171016143000_added_additional_columns2.php diff --git a/src/PHPCensor/Migrations/20171019143346_added_additional_columns3.php b/src/Migrations/20171019143346_added_additional_columns3.php similarity index 100% rename from src/PHPCensor/Migrations/20171019143346_added_additional_columns3.php rename to src/Migrations/20171019143346_added_additional_columns3.php diff --git a/src/PHPCensor/Migrations/20171209135004_added_new_label_for_errors.php b/src/Migrations/20171209135004_added_new_label_for_errors.php similarity index 100% rename from src/PHPCensor/Migrations/20171209135004_added_new_label_for_errors.php rename to src/Migrations/20171209135004_added_new_label_for_errors.php diff --git a/src/PHPCensor/Migrations/20180223052715_added_request_branch_to_build.php b/src/Migrations/20180223052715_added_request_branch_to_build.php similarity index 100% rename from src/PHPCensor/Migrations/20180223052715_added_request_branch_to_build.php rename to src/Migrations/20180223052715_added_request_branch_to_build.php diff --git a/src/PHPCensor/Migrations/20180228024622_renamed_build_types.php b/src/Migrations/20180228024622_renamed_build_types.php similarity index 100% rename from src/PHPCensor/Migrations/20180228024622_renamed_build_types.php rename to src/Migrations/20180228024622_renamed_build_types.php diff --git a/src/PHPCensor/Model.php b/src/Model.php similarity index 100% rename from src/PHPCensor/Model.php rename to src/Model.php diff --git a/src/PHPCensor/Model/Build.php b/src/Model/Build.php similarity index 100% rename from src/PHPCensor/Model/Build.php rename to src/Model/Build.php diff --git a/src/PHPCensor/Model/Build/BitbucketBuild.php b/src/Model/Build/BitbucketBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/BitbucketBuild.php rename to src/Model/Build/BitbucketBuild.php diff --git a/src/PHPCensor/Model/Build/BitbucketHgBuild.php b/src/Model/Build/BitbucketHgBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/BitbucketHgBuild.php rename to src/Model/Build/BitbucketHgBuild.php diff --git a/src/PHPCensor/Model/Build/GitBuild.php b/src/Model/Build/GitBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/GitBuild.php rename to src/Model/Build/GitBuild.php diff --git a/src/PHPCensor/Model/Build/GithubBuild.php b/src/Model/Build/GithubBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/GithubBuild.php rename to src/Model/Build/GithubBuild.php diff --git a/src/PHPCensor/Model/Build/GitlabBuild.php b/src/Model/Build/GitlabBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/GitlabBuild.php rename to src/Model/Build/GitlabBuild.php diff --git a/src/PHPCensor/Model/Build/GogsBuild.php b/src/Model/Build/GogsBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/GogsBuild.php rename to src/Model/Build/GogsBuild.php diff --git a/src/PHPCensor/Model/Build/HgBuild.php b/src/Model/Build/HgBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/HgBuild.php rename to src/Model/Build/HgBuild.php diff --git a/src/PHPCensor/Model/Build/LocalBuild.php b/src/Model/Build/LocalBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/LocalBuild.php rename to src/Model/Build/LocalBuild.php diff --git a/src/PHPCensor/Model/Build/SvnBuild.php b/src/Model/Build/SvnBuild.php similarity index 100% rename from src/PHPCensor/Model/Build/SvnBuild.php rename to src/Model/Build/SvnBuild.php diff --git a/src/PHPCensor/Model/BuildError.php b/src/Model/BuildError.php similarity index 100% rename from src/PHPCensor/Model/BuildError.php rename to src/Model/BuildError.php diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/Model/BuildMeta.php similarity index 100% rename from src/PHPCensor/Model/BuildMeta.php rename to src/Model/BuildMeta.php diff --git a/src/PHPCensor/Model/Environment.php b/src/Model/Environment.php similarity index 100% rename from src/PHPCensor/Model/Environment.php rename to src/Model/Environment.php diff --git a/src/PHPCensor/Model/Project.php b/src/Model/Project.php similarity index 100% rename from src/PHPCensor/Model/Project.php rename to src/Model/Project.php diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/Model/ProjectGroup.php similarity index 100% rename from src/PHPCensor/Model/ProjectGroup.php rename to src/Model/ProjectGroup.php diff --git a/src/PHPCensor/Model/User.php b/src/Model/User.php similarity index 100% rename from src/PHPCensor/Model/User.php rename to src/Model/User.php diff --git a/src/PHPCensor/Plugin.php b/src/Plugin.php similarity index 100% rename from src/PHPCensor/Plugin.php rename to src/Plugin.php diff --git a/src/PHPCensor/Plugin/Atoum.php b/src/Plugin/Atoum.php similarity index 100% rename from src/PHPCensor/Plugin/Atoum.php rename to src/Plugin/Atoum.php diff --git a/src/PHPCensor/Plugin/Behat.php b/src/Plugin/Behat.php similarity index 100% rename from src/PHPCensor/Plugin/Behat.php rename to src/Plugin/Behat.php diff --git a/src/PHPCensor/Plugin/Campfire.php b/src/Plugin/Campfire.php similarity index 100% rename from src/PHPCensor/Plugin/Campfire.php rename to src/Plugin/Campfire.php diff --git a/src/PHPCensor/Plugin/CleanBuild.php b/src/Plugin/CleanBuild.php similarity index 100% rename from src/PHPCensor/Plugin/CleanBuild.php rename to src/Plugin/CleanBuild.php diff --git a/src/PHPCensor/Plugin/Codeception.php b/src/Plugin/Codeception.php similarity index 100% rename from src/PHPCensor/Plugin/Codeception.php rename to src/Plugin/Codeception.php diff --git a/src/PHPCensor/Plugin/Composer.php b/src/Plugin/Composer.php similarity index 100% rename from src/PHPCensor/Plugin/Composer.php rename to src/Plugin/Composer.php diff --git a/src/PHPCensor/Plugin/CopyBuild.php b/src/Plugin/CopyBuild.php similarity index 100% rename from src/PHPCensor/Plugin/CopyBuild.php rename to src/Plugin/CopyBuild.php diff --git a/src/PHPCensor/Plugin/Deployer.php b/src/Plugin/Deployer.php similarity index 100% rename from src/PHPCensor/Plugin/Deployer.php rename to src/Plugin/Deployer.php diff --git a/src/PHPCensor/Plugin/Email.php b/src/Plugin/Email.php similarity index 100% rename from src/PHPCensor/Plugin/Email.php rename to src/Plugin/Email.php diff --git a/src/PHPCensor/Plugin/Env.php b/src/Plugin/Env.php similarity index 100% rename from src/PHPCensor/Plugin/Env.php rename to src/Plugin/Env.php diff --git a/src/PHPCensor/Plugin/FlowdockNotify.php b/src/Plugin/FlowdockNotify.php similarity index 100% rename from src/PHPCensor/Plugin/FlowdockNotify.php rename to src/Plugin/FlowdockNotify.php diff --git a/src/PHPCensor/Plugin/Git.php b/src/Plugin/Git.php similarity index 100% rename from src/PHPCensor/Plugin/Git.php rename to src/Plugin/Git.php diff --git a/src/PHPCensor/Plugin/Grunt.php b/src/Plugin/Grunt.php similarity index 100% rename from src/PHPCensor/Plugin/Grunt.php rename to src/Plugin/Grunt.php diff --git a/src/PHPCensor/Plugin/Gulp.php b/src/Plugin/Gulp.php similarity index 100% rename from src/PHPCensor/Plugin/Gulp.php rename to src/Plugin/Gulp.php diff --git a/src/PHPCensor/Plugin/HipchatNotify.php b/src/Plugin/HipchatNotify.php similarity index 100% rename from src/PHPCensor/Plugin/HipchatNotify.php rename to src/Plugin/HipchatNotify.php diff --git a/src/PHPCensor/Plugin/Irc.php b/src/Plugin/Irc.php similarity index 100% rename from src/PHPCensor/Plugin/Irc.php rename to src/Plugin/Irc.php diff --git a/src/PHPCensor/Plugin/Lint.php b/src/Plugin/Lint.php similarity index 100% rename from src/PHPCensor/Plugin/Lint.php rename to src/Plugin/Lint.php diff --git a/src/PHPCensor/Plugin/Mage.php b/src/Plugin/Mage.php similarity index 100% rename from src/PHPCensor/Plugin/Mage.php rename to src/Plugin/Mage.php diff --git a/src/PHPCensor/Plugin/Mage3.php b/src/Plugin/Mage3.php similarity index 100% rename from src/PHPCensor/Plugin/Mage3.php rename to src/Plugin/Mage3.php diff --git a/src/PHPCensor/Plugin/Mysql.php b/src/Plugin/Mysql.php similarity index 100% rename from src/PHPCensor/Plugin/Mysql.php rename to src/Plugin/Mysql.php diff --git a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php b/src/Plugin/Option/PhpUnitOptions.php similarity index 100% rename from src/PHPCensor/Plugin/Option/PhpUnitOptions.php rename to src/Plugin/Option/PhpUnitOptions.php diff --git a/src/PHPCensor/Plugin/PackageBuild.php b/src/Plugin/PackageBuild.php similarity index 100% rename from src/PHPCensor/Plugin/PackageBuild.php rename to src/Plugin/PackageBuild.php diff --git a/src/PHPCensor/Plugin/Pdepend.php b/src/Plugin/Pdepend.php similarity index 100% rename from src/PHPCensor/Plugin/Pdepend.php rename to src/Plugin/Pdepend.php diff --git a/src/PHPCensor/Plugin/Pgsql.php b/src/Plugin/Pgsql.php similarity index 100% rename from src/PHPCensor/Plugin/Pgsql.php rename to src/Plugin/Pgsql.php diff --git a/src/PHPCensor/Plugin/Phar.php b/src/Plugin/Phar.php similarity index 100% rename from src/PHPCensor/Plugin/Phar.php rename to src/Plugin/Phar.php diff --git a/src/PHPCensor/Plugin/Phing.php b/src/Plugin/Phing.php similarity index 100% rename from src/PHPCensor/Plugin/Phing.php rename to src/Plugin/Phing.php diff --git a/src/PHPCensor/Plugin/PhpCodeSniffer.php b/src/Plugin/PhpCodeSniffer.php similarity index 100% rename from src/PHPCensor/Plugin/PhpCodeSniffer.php rename to src/Plugin/PhpCodeSniffer.php diff --git a/src/PHPCensor/Plugin/PhpCpd.php b/src/Plugin/PhpCpd.php similarity index 100% rename from src/PHPCensor/Plugin/PhpCpd.php rename to src/Plugin/PhpCpd.php diff --git a/src/PHPCensor/Plugin/PhpCsFixer.php b/src/Plugin/PhpCsFixer.php similarity index 100% rename from src/PHPCensor/Plugin/PhpCsFixer.php rename to src/Plugin/PhpCsFixer.php diff --git a/src/PHPCensor/Plugin/PhpDocblockChecker.php b/src/Plugin/PhpDocblockChecker.php similarity index 100% rename from src/PHPCensor/Plugin/PhpDocblockChecker.php rename to src/Plugin/PhpDocblockChecker.php diff --git a/src/PHPCensor/Plugin/PhpLoc.php b/src/Plugin/PhpLoc.php similarity index 100% rename from src/PHPCensor/Plugin/PhpLoc.php rename to src/Plugin/PhpLoc.php diff --git a/src/PHPCensor/Plugin/PhpMessDetector.php b/src/Plugin/PhpMessDetector.php similarity index 100% rename from src/PHPCensor/Plugin/PhpMessDetector.php rename to src/Plugin/PhpMessDetector.php diff --git a/src/PHPCensor/Plugin/PhpParallelLint.php b/src/Plugin/PhpParallelLint.php similarity index 100% rename from src/PHPCensor/Plugin/PhpParallelLint.php rename to src/Plugin/PhpParallelLint.php diff --git a/src/PHPCensor/Plugin/PhpSpec.php b/src/Plugin/PhpSpec.php similarity index 100% rename from src/PHPCensor/Plugin/PhpSpec.php rename to src/Plugin/PhpSpec.php diff --git a/src/PHPCensor/Plugin/PhpTalLint.php b/src/Plugin/PhpTalLint.php similarity index 98% rename from src/PHPCensor/Plugin/PhpTalLint.php rename to src/Plugin/PhpTalLint.php index 636df1e2..1f2c784d 100644 --- a/src/PHPCensor/Plugin/PhpTalLint.php +++ b/src/Plugin/PhpTalLint.php @@ -9,7 +9,7 @@ use PHPCensor\Plugin; /** * PHPTAL Lint Plugin - Provides access to PHPTAL lint functionality. - * + * * @author Stephen Ball */ class PhpTalLint extends Plugin @@ -174,7 +174,7 @@ class PhpTalLint extends Plugin list($suffixes, $tales) = $this->getFlags(); - $lint = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; + $lint = __DIR__ . DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; $lint .= 'vendor' . DIRECTORY_SEPARATOR . 'phptal' . DIRECTORY_SEPARATOR . 'phptal' . DIRECTORY_SEPARATOR; $lint .= 'tools' . DIRECTORY_SEPARATOR . 'phptal_lint.php'; $cmd = '/usr/bin/env php ' . $lint . ' %s %s "%s"'; diff --git a/src/PHPCensor/Plugin/PhpUnit.php b/src/Plugin/PhpUnit.php similarity index 100% rename from src/PHPCensor/Plugin/PhpUnit.php rename to src/Plugin/PhpUnit.php diff --git a/src/PHPCensor/Plugin/SecurityChecker.php b/src/Plugin/SecurityChecker.php similarity index 100% rename from src/PHPCensor/Plugin/SecurityChecker.php rename to src/Plugin/SecurityChecker.php diff --git a/src/PHPCensor/Plugin/Shell.php b/src/Plugin/Shell.php similarity index 100% rename from src/PHPCensor/Plugin/Shell.php rename to src/Plugin/Shell.php diff --git a/src/PHPCensor/Plugin/SlackNotify.php b/src/Plugin/SlackNotify.php similarity index 100% rename from src/PHPCensor/Plugin/SlackNotify.php rename to src/Plugin/SlackNotify.php diff --git a/src/PHPCensor/Plugin/Sqlite.php b/src/Plugin/Sqlite.php similarity index 100% rename from src/PHPCensor/Plugin/Sqlite.php rename to src/Plugin/Sqlite.php diff --git a/src/PHPCensor/Plugin/TechnicalDebt.php b/src/Plugin/TechnicalDebt.php similarity index 100% rename from src/PHPCensor/Plugin/TechnicalDebt.php rename to src/Plugin/TechnicalDebt.php diff --git a/src/PHPCensor/Plugin/Util/Executor.php b/src/Plugin/Util/Executor.php similarity index 100% rename from src/PHPCensor/Plugin/Util/Executor.php rename to src/Plugin/Util/Executor.php diff --git a/src/PHPCensor/Plugin/Util/Factory.php b/src/Plugin/Util/Factory.php similarity index 100% rename from src/PHPCensor/Plugin/Util/Factory.php rename to src/Plugin/Util/Factory.php diff --git a/src/PHPCensor/Plugin/Util/PhpUnitResult.php b/src/Plugin/Util/PhpUnitResult.php similarity index 100% rename from src/PHPCensor/Plugin/Util/PhpUnitResult.php rename to src/Plugin/Util/PhpUnitResult.php diff --git a/src/PHPCensor/Plugin/Util/PhpUnitResultJson.php b/src/Plugin/Util/PhpUnitResultJson.php similarity index 100% rename from src/PHPCensor/Plugin/Util/PhpUnitResultJson.php rename to src/Plugin/Util/PhpUnitResultJson.php diff --git a/src/PHPCensor/Plugin/Util/PhpUnitResultJunit.php b/src/Plugin/Util/PhpUnitResultJunit.php similarity index 100% rename from src/PHPCensor/Plugin/Util/PhpUnitResultJunit.php rename to src/Plugin/Util/PhpUnitResultJunit.php diff --git a/src/PHPCensor/Plugin/Util/TestResultParsers/Codeception.php b/src/Plugin/Util/TestResultParsers/Codeception.php similarity index 100% rename from src/PHPCensor/Plugin/Util/TestResultParsers/Codeception.php rename to src/Plugin/Util/TestResultParsers/Codeception.php diff --git a/src/PHPCensor/Plugin/Util/TestResultParsers/ParserInterface.php b/src/Plugin/Util/TestResultParsers/ParserInterface.php similarity index 100% rename from src/PHPCensor/Plugin/Util/TestResultParsers/ParserInterface.php rename to src/Plugin/Util/TestResultParsers/ParserInterface.php diff --git a/src/PHPCensor/Plugin/Wipe.php b/src/Plugin/Wipe.php similarity index 100% rename from src/PHPCensor/Plugin/Wipe.php rename to src/Plugin/Wipe.php diff --git a/src/PHPCensor/Plugin/Xmpp.php b/src/Plugin/Xmpp.php similarity index 100% rename from src/PHPCensor/Plugin/Xmpp.php rename to src/Plugin/Xmpp.php diff --git a/src/PHPCensor/ProcessControl/Factory.php b/src/ProcessControl/Factory.php similarity index 100% rename from src/PHPCensor/ProcessControl/Factory.php rename to src/ProcessControl/Factory.php diff --git a/src/PHPCensor/ProcessControl/PosixProcessControl.php b/src/ProcessControl/PosixProcessControl.php similarity index 100% rename from src/PHPCensor/ProcessControl/PosixProcessControl.php rename to src/ProcessControl/PosixProcessControl.php diff --git a/src/PHPCensor/ProcessControl/ProcessControlInterface.php b/src/ProcessControl/ProcessControlInterface.php similarity index 100% rename from src/PHPCensor/ProcessControl/ProcessControlInterface.php rename to src/ProcessControl/ProcessControlInterface.php diff --git a/src/PHPCensor/ProcessControl/UnixProcessControl.php b/src/ProcessControl/UnixProcessControl.php similarity index 100% rename from src/PHPCensor/ProcessControl/UnixProcessControl.php rename to src/ProcessControl/UnixProcessControl.php diff --git a/src/PHPCensor/Security/Authentication/LoginPasswordProviderInterface.php b/src/Security/Authentication/LoginPasswordProviderInterface.php similarity index 100% rename from src/PHPCensor/Security/Authentication/LoginPasswordProviderInterface.php rename to src/Security/Authentication/LoginPasswordProviderInterface.php diff --git a/src/PHPCensor/Security/Authentication/Service.php b/src/Security/Authentication/Service.php similarity index 100% rename from src/PHPCensor/Security/Authentication/Service.php rename to src/Security/Authentication/Service.php diff --git a/src/PHPCensor/Security/Authentication/UserProvider/AbstractProvider.php b/src/Security/Authentication/UserProvider/AbstractProvider.php similarity index 100% rename from src/PHPCensor/Security/Authentication/UserProvider/AbstractProvider.php rename to src/Security/Authentication/UserProvider/AbstractProvider.php diff --git a/src/PHPCensor/Security/Authentication/UserProvider/Internal.php b/src/Security/Authentication/UserProvider/Internal.php similarity index 100% rename from src/PHPCensor/Security/Authentication/UserProvider/Internal.php rename to src/Security/Authentication/UserProvider/Internal.php diff --git a/src/PHPCensor/Security/Authentication/UserProvider/Ldap.php b/src/Security/Authentication/UserProvider/Ldap.php similarity index 100% rename from src/PHPCensor/Security/Authentication/UserProvider/Ldap.php rename to src/Security/Authentication/UserProvider/Ldap.php diff --git a/src/PHPCensor/Security/Authentication/UserProviderInterface.php b/src/Security/Authentication/UserProviderInterface.php similarity index 100% rename from src/PHPCensor/Security/Authentication/UserProviderInterface.php rename to src/Security/Authentication/UserProviderInterface.php diff --git a/src/PHPCensor/Service/BuildService.php b/src/Service/BuildService.php similarity index 100% rename from src/PHPCensor/Service/BuildService.php rename to src/Service/BuildService.php diff --git a/src/PHPCensor/Service/BuildStatusService.php b/src/Service/BuildStatusService.php similarity index 100% rename from src/PHPCensor/Service/BuildStatusService.php rename to src/Service/BuildStatusService.php diff --git a/src/PHPCensor/Service/ProjectService.php b/src/Service/ProjectService.php similarity index 100% rename from src/PHPCensor/Service/ProjectService.php rename to src/Service/ProjectService.php diff --git a/src/PHPCensor/Service/UserService.php b/src/Service/UserService.php similarity index 100% rename from src/PHPCensor/Service/UserService.php rename to src/Service/UserService.php diff --git a/src/PHPCensor/Store.php b/src/Store.php similarity index 100% rename from src/PHPCensor/Store.php rename to src/Store.php diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/Store/BuildErrorStore.php similarity index 100% rename from src/PHPCensor/Store/BuildErrorStore.php rename to src/Store/BuildErrorStore.php diff --git a/src/PHPCensor/Store/BuildErrorWriter.php b/src/Store/BuildErrorWriter.php similarity index 100% rename from src/PHPCensor/Store/BuildErrorWriter.php rename to src/Store/BuildErrorWriter.php diff --git a/src/PHPCensor/Store/BuildMetaStore.php b/src/Store/BuildMetaStore.php similarity index 100% rename from src/PHPCensor/Store/BuildMetaStore.php rename to src/Store/BuildMetaStore.php diff --git a/src/PHPCensor/Store/BuildStore.php b/src/Store/BuildStore.php similarity index 100% rename from src/PHPCensor/Store/BuildStore.php rename to src/Store/BuildStore.php diff --git a/src/PHPCensor/Store/EnvironmentStore.php b/src/Store/EnvironmentStore.php similarity index 100% rename from src/PHPCensor/Store/EnvironmentStore.php rename to src/Store/EnvironmentStore.php diff --git a/src/PHPCensor/Store/Factory.php b/src/Store/Factory.php similarity index 100% rename from src/PHPCensor/Store/Factory.php rename to src/Store/Factory.php diff --git a/src/PHPCensor/Store/ProjectGroupStore.php b/src/Store/ProjectGroupStore.php similarity index 100% rename from src/PHPCensor/Store/ProjectGroupStore.php rename to src/Store/ProjectGroupStore.php diff --git a/src/PHPCensor/Store/ProjectStore.php b/src/Store/ProjectStore.php similarity index 100% rename from src/PHPCensor/Store/ProjectStore.php rename to src/Store/ProjectStore.php diff --git a/src/PHPCensor/Store/UserStore.php b/src/Store/UserStore.php similarity index 100% rename from src/PHPCensor/Store/UserStore.php rename to src/Store/UserStore.php diff --git a/src/PHPCensor/View.php b/src/View.php similarity index 100% rename from src/PHPCensor/View.php rename to src/View.php diff --git a/src/PHPCensor/View/Build/errors.phtml b/src/View/Build/errors.phtml similarity index 100% rename from src/PHPCensor/View/Build/errors.phtml rename to src/View/Build/errors.phtml diff --git a/src/PHPCensor/View/Build/header-row.phtml b/src/View/Build/header-row.phtml similarity index 100% rename from src/PHPCensor/View/Build/header-row.phtml rename to src/View/Build/header-row.phtml diff --git a/src/PHPCensor/View/Build/view.phtml b/src/View/Build/view.phtml similarity index 100% rename from src/PHPCensor/View/Build/view.phtml rename to src/View/Build/view.phtml diff --git a/src/PHPCensor/View/BuildStatus/view.phtml b/src/View/BuildStatus/view.phtml similarity index 100% rename from src/PHPCensor/View/BuildStatus/view.phtml rename to src/View/BuildStatus/view.phtml diff --git a/src/PHPCensor/View/Email/layout.phtml b/src/View/Email/layout.phtml similarity index 93% rename from src/PHPCensor/View/Email/layout.phtml rename to src/View/Email/layout.phtml index a97ac991..b4fbad83 100644 --- a/src/PHPCensor/View/Email/layout.phtml +++ b/src/View/Email/layout.phtml @@ -1,7 +1,7 @@ diff --git a/src/PHPCensor/View/Email/long.phtml b/src/View/Email/long.phtml similarity index 100% rename from src/PHPCensor/View/Email/long.phtml rename to src/View/Email/long.phtml diff --git a/src/PHPCensor/View/Email/short.phtml b/src/View/Email/short.phtml similarity index 100% rename from src/PHPCensor/View/Email/short.phtml rename to src/View/Email/short.phtml diff --git a/src/PHPCensor/Form/View/Button.phtml b/src/View/Form/Button.phtml similarity index 100% rename from src/PHPCensor/Form/View/Button.phtml rename to src/View/Form/Button.phtml diff --git a/src/PHPCensor/Form/View/Checkbox.phtml b/src/View/Form/Checkbox.phtml similarity index 100% rename from src/PHPCensor/Form/View/Checkbox.phtml rename to src/View/Form/Checkbox.phtml diff --git a/src/PHPCensor/Form/View/CheckboxGroup.phtml b/src/View/Form/CheckboxGroup.phtml similarity index 100% rename from src/PHPCensor/Form/View/CheckboxGroup.phtml rename to src/View/Form/CheckboxGroup.phtml diff --git a/src/PHPCensor/Form/View/ControlGroup.phtml b/src/View/Form/ControlGroup.phtml similarity index 100% rename from src/PHPCensor/Form/View/ControlGroup.phtml rename to src/View/Form/ControlGroup.phtml diff --git a/src/PHPCensor/Form/View/Csrf.phtml b/src/View/Form/Csrf.phtml similarity index 100% rename from src/PHPCensor/Form/View/Csrf.phtml rename to src/View/Form/Csrf.phtml diff --git a/src/PHPCensor/Form/View/FieldSet.phtml b/src/View/Form/FieldSet.phtml similarity index 100% rename from src/PHPCensor/Form/View/FieldSet.phtml rename to src/View/Form/FieldSet.phtml diff --git a/src/PHPCensor/Form/View/Form.phtml b/src/View/Form/Form.phtml similarity index 100% rename from src/PHPCensor/Form/View/Form.phtml rename to src/View/Form/Form.phtml diff --git a/src/PHPCensor/Form/View/Hidden.phtml b/src/View/Form/Hidden.phtml similarity index 100% rename from src/PHPCensor/Form/View/Hidden.phtml rename to src/View/Form/Hidden.phtml diff --git a/src/PHPCensor/Form/View/Radio.phtml b/src/View/Form/Radio.phtml similarity index 100% rename from src/PHPCensor/Form/View/Radio.phtml rename to src/View/Form/Radio.phtml diff --git a/src/PHPCensor/Form/View/Select.phtml b/src/View/Form/Select.phtml similarity index 100% rename from src/PHPCensor/Form/View/Select.phtml rename to src/View/Form/Select.phtml diff --git a/src/PHPCensor/Form/View/Text.phtml b/src/View/Form/Text.phtml similarity index 100% rename from src/PHPCensor/Form/View/Text.phtml rename to src/View/Form/Text.phtml diff --git a/src/PHPCensor/Form/View/TextArea.phtml b/src/View/Form/TextArea.phtml similarity index 100% rename from src/PHPCensor/Form/View/TextArea.phtml rename to src/View/Form/TextArea.phtml diff --git a/src/PHPCensor/View/Group/edit.phtml b/src/View/Group/edit.phtml similarity index 100% rename from src/PHPCensor/View/Group/edit.phtml rename to src/View/Group/edit.phtml diff --git a/src/PHPCensor/View/Group/index.phtml b/src/View/Group/index.phtml similarity index 100% rename from src/PHPCensor/View/Group/index.phtml rename to src/View/Group/index.phtml diff --git a/src/PHPCensor/View/Home/index.phtml b/src/View/Home/index.phtml similarity index 100% rename from src/PHPCensor/View/Home/index.phtml rename to src/View/Home/index.phtml diff --git a/src/PHPCensor/View/Project/ajax-builds.phtml b/src/View/Project/ajax-builds.phtml similarity index 100% rename from src/PHPCensor/View/Project/ajax-builds.phtml rename to src/View/Project/ajax-builds.phtml diff --git a/src/PHPCensor/View/Project/edit.phtml b/src/View/Project/edit.phtml similarity index 100% rename from src/PHPCensor/View/Project/edit.phtml rename to src/View/Project/edit.phtml diff --git a/src/PHPCensor/View/Project/view.phtml b/src/View/Project/view.phtml similarity index 100% rename from src/PHPCensor/View/Project/view.phtml rename to src/View/Project/view.phtml diff --git a/src/PHPCensor/View/Session.phtml b/src/View/Session.phtml similarity index 100% rename from src/PHPCensor/View/Session.phtml rename to src/View/Session.phtml diff --git a/src/PHPCensor/View/Session/forgotPassword.phtml b/src/View/Session/forgotPassword.phtml similarity index 100% rename from src/PHPCensor/View/Session/forgotPassword.phtml rename to src/View/Session/forgotPassword.phtml diff --git a/src/PHPCensor/View/Session/login.phtml b/src/View/Session/login.phtml similarity index 100% rename from src/PHPCensor/View/Session/login.phtml rename to src/View/Session/login.phtml diff --git a/src/PHPCensor/View/Session/resetPassword.phtml b/src/View/Session/resetPassword.phtml similarity index 100% rename from src/PHPCensor/View/Session/resetPassword.phtml rename to src/View/Session/resetPassword.phtml diff --git a/src/PHPCensor/View/User/edit.phtml b/src/View/User/edit.phtml similarity index 100% rename from src/PHPCensor/View/User/edit.phtml rename to src/View/User/edit.phtml diff --git a/src/PHPCensor/View/User/index.phtml b/src/View/User/index.phtml similarity index 100% rename from src/PHPCensor/View/User/index.phtml rename to src/View/User/index.phtml diff --git a/src/PHPCensor/View/User/profile.phtml b/src/View/User/profile.phtml similarity index 100% rename from src/PHPCensor/View/User/profile.phtml rename to src/View/User/profile.phtml diff --git a/src/PHPCensor/View/WidgetAllProjects/index-projects.phtml b/src/View/WidgetAllProjects/index-projects.phtml similarity index 100% rename from src/PHPCensor/View/WidgetAllProjects/index-projects.phtml rename to src/View/WidgetAllProjects/index-projects.phtml diff --git a/src/PHPCensor/View/WidgetAllProjects/index.phtml b/src/View/WidgetAllProjects/index.phtml similarity index 100% rename from src/PHPCensor/View/WidgetAllProjects/index.phtml rename to src/View/WidgetAllProjects/index.phtml diff --git a/src/PHPCensor/View/WidgetAllProjects/update.phtml b/src/View/WidgetAllProjects/update.phtml similarity index 100% rename from src/PHPCensor/View/WidgetAllProjects/update.phtml rename to src/View/WidgetAllProjects/update.phtml diff --git a/src/PHPCensor/View/WidgetBuildErrors/empty.phtml b/src/View/WidgetBuildErrors/empty.phtml similarity index 100% rename from src/PHPCensor/View/WidgetBuildErrors/empty.phtml rename to src/View/WidgetBuildErrors/empty.phtml diff --git a/src/PHPCensor/View/WidgetBuildErrors/index.phtml b/src/View/WidgetBuildErrors/index.phtml similarity index 100% rename from src/PHPCensor/View/WidgetBuildErrors/index.phtml rename to src/View/WidgetBuildErrors/index.phtml diff --git a/src/PHPCensor/View/WidgetBuildErrors/update.phtml b/src/View/WidgetBuildErrors/update.phtml similarity index 100% rename from src/PHPCensor/View/WidgetBuildErrors/update.phtml rename to src/View/WidgetBuildErrors/update.phtml diff --git a/src/PHPCensor/View/WidgetLastBuilds/index.phtml b/src/View/WidgetLastBuilds/index.phtml similarity index 100% rename from src/PHPCensor/View/WidgetLastBuilds/index.phtml rename to src/View/WidgetLastBuilds/index.phtml diff --git a/src/PHPCensor/View/WidgetLastBuilds/update.phtml b/src/View/WidgetLastBuilds/update.phtml similarity index 100% rename from src/PHPCensor/View/WidgetLastBuilds/update.phtml rename to src/View/WidgetLastBuilds/update.phtml diff --git a/src/PHPCensor/View/exception.phtml b/src/View/exception.phtml similarity index 100% rename from src/PHPCensor/View/exception.phtml rename to src/View/exception.phtml diff --git a/src/PHPCensor/View/layout.phtml b/src/View/layout.phtml similarity index 100% rename from src/PHPCensor/View/layout.phtml rename to src/View/layout.phtml diff --git a/src/PHPCensor/View/pagination.phtml b/src/View/pagination.phtml similarity index 100% rename from src/PHPCensor/View/pagination.phtml rename to src/View/pagination.phtml diff --git a/src/PHPCensor/Worker/BuildWorker.php b/src/Worker/BuildWorker.php similarity index 100% rename from src/PHPCensor/Worker/BuildWorker.php rename to src/Worker/BuildWorker.php diff --git a/src/PHPCensor/ZeroConfigPluginInterface.php b/src/ZeroConfigPluginInterface.php similarity index 100% rename from src/PHPCensor/ZeroConfigPluginInterface.php rename to src/ZeroConfigPluginInterface.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 906f8c5a..0783ef40 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,7 +5,7 @@ if (!defined('ROOT_DIR')) { } if (!defined('SRC_DIR')) { - define('SRC_DIR', ROOT_DIR . 'src/PHPCensor/'); + define('SRC_DIR', ROOT_DIR . 'src/'); } if (!defined('PUBLIC_DIR')) { diff --git a/tests/PHPCensor/Plugin/SampleFiles/invalid_format.txt b/tests/data/Plugin/PhpUnit/invalid_format.txt similarity index 100% rename from tests/PHPCensor/Plugin/SampleFiles/invalid_format.txt rename to tests/data/Plugin/PhpUnit/invalid_format.txt diff --git a/tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt b/tests/data/Plugin/PhpUnit/phpunit_money.txt similarity index 100% rename from tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt rename to tests/data/Plugin/PhpUnit/phpunit_money.txt diff --git a/tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml b/tests/data/Plugin/PhpUnit/phpunit_money_junit.xml similarity index 100% rename from tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml rename to tests/data/Plugin/PhpUnit/phpunit_money_junit.xml diff --git a/tests/PHPCensor/data/view/Form/form.phtml b/tests/data/View/Form/form.phtml similarity index 100% rename from tests/PHPCensor/data/view/Form/form.phtml rename to tests/data/View/Form/form.phtml diff --git a/tests/PHPCensor/data/view/simple.phtml b/tests/data/View/simple.phtml similarity index 100% rename from tests/PHPCensor/data/view/simple.phtml rename to tests/data/View/simple.phtml diff --git a/tests/PHPCensor/data/view/vars.phtml b/tests/data/View/vars.phtml similarity index 100% rename from tests/PHPCensor/data/view/vars.phtml rename to tests/data/View/vars.phtml diff --git a/tests/temp/.gitkeep b/tests/runtime/.gitkeep similarity index 100% rename from tests/temp/.gitkeep rename to tests/runtime/.gitkeep diff --git a/tests/PHPCensor/Command/CreateAdminCommandTest.php b/tests/src/Command/CreateAdminCommandTest.php similarity index 97% rename from tests/PHPCensor/Command/CreateAdminCommandTest.php rename to tests/src/Command/CreateAdminCommandTest.php index a4be00ec..7ec0877c 100644 --- a/tests/PHPCensor/Command/CreateAdminCommandTest.php +++ b/tests/src/Command/CreateAdminCommandTest.php @@ -1,6 +1,6 @@ mockFactory->buildPlugin($pluginNamespace . $pluginName, $options) - ->shouldBeCalledTimes(1) - ->willReturn($this->prophesize('PHPCensor\Plugin')->reveal()); + $this->mockFactory + ->buildPlugin($pluginNamespace . $pluginName, $options) + ->shouldBeCalledTimes(1) + ->willReturn($this->prophesize('PHPCensor\Plugin')->reveal()); $this->testedExecutor->executePlugin($pluginName, $options); } @@ -56,9 +57,10 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase $options = []; $pluginClass = $this->getFakePluginClassName('ExamplePluginFull'); - $this->mockFactory->buildPlugin($pluginClass, $options) - ->shouldBeCalledTimes(1) - ->willReturn($this->prophesize('PHPCensor\Plugin')->reveal()); + $this->mockFactory + ->buildPlugin($pluginClass, $options) + ->shouldBeCalledTimes(1) + ->willReturn($this->prophesize('PHPCensor\Plugin')->reveal()); $this->testedExecutor->executePlugin($pluginClass, $options); } diff --git a/tests/PHPCensor/Plugin/Util/FactoryTest.php b/tests/src/Plugin/Util/FactoryTest.php similarity index 100% rename from tests/PHPCensor/Plugin/Util/FactoryTest.php rename to tests/src/Plugin/Util/FactoryTest.php diff --git a/tests/PHPCensor/Plugin/Util/Fake/ExamplePluginFull.php b/tests/src/Plugin/Util/Fake/ExamplePluginFull.php similarity index 100% rename from tests/PHPCensor/Plugin/Util/Fake/ExamplePluginFull.php rename to tests/src/Plugin/Util/Fake/ExamplePluginFull.php diff --git a/tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithNoConstructorArgs.php b/tests/src/Plugin/Util/Fake/ExamplePluginWithNoConstructorArgs.php similarity index 100% rename from tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithNoConstructorArgs.php rename to tests/src/Plugin/Util/Fake/ExamplePluginWithNoConstructorArgs.php diff --git a/tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithSingleOptionalArg.php b/tests/src/Plugin/Util/Fake/ExamplePluginWithSingleOptionalArg.php similarity index 100% rename from tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithSingleOptionalArg.php rename to tests/src/Plugin/Util/Fake/ExamplePluginWithSingleOptionalArg.php diff --git a/tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithSingleRequiredArg.php b/tests/src/Plugin/Util/Fake/ExamplePluginWithSingleRequiredArg.php similarity index 100% rename from tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithSingleRequiredArg.php rename to tests/src/Plugin/Util/Fake/ExamplePluginWithSingleRequiredArg.php diff --git a/tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithSingleTypedRequiredArg.php b/tests/src/Plugin/Util/Fake/ExamplePluginWithSingleTypedRequiredArg.php similarity index 100% rename from tests/PHPCensor/Plugin/Util/Fake/ExamplePluginWithSingleTypedRequiredArg.php rename to tests/src/Plugin/Util/Fake/ExamplePluginWithSingleTypedRequiredArg.php diff --git a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php b/tests/src/Plugin/Util/PhpUnitResultTest.php similarity index 93% rename from tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php rename to tests/src/Plugin/Util/PhpUnitResultTest.php index 9eeaa50a..d16bde0c 100644 --- a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php +++ b/tests/src/Plugin/Util/PhpUnitResultTest.php @@ -83,8 +83,8 @@ class PhpUnitResultTest extends \PHPUnit\Framework\TestCase public static function getTestData() { return [ - 'json' => [PhpUnitResultJson::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt'], - 'junit' => [PhpUnitResultJunit::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml'], + 'json' => [PhpUnitResultJson::class, 'tests/data/Plugin/PhpUnit/phpunit_money.txt'], + 'junit' => [PhpUnitResultJunit::class, 'tests/data/Plugin/PhpUnit/phpunit_money_junit.xml'], ]; } } diff --git a/tests/PHPCensor/ProcessControl/PosixProcessControlTest.php b/tests/src/ProcessControl/PosixProcessControlTest.php similarity index 99% rename from tests/PHPCensor/ProcessControl/PosixProcessControlTest.php rename to tests/src/ProcessControl/PosixProcessControlTest.php index 2e46e356..4b46ead8 100644 --- a/tests/PHPCensor/ProcessControl/PosixProcessControlTest.php +++ b/tests/src/ProcessControl/PosixProcessControlTest.php @@ -1,4 +1,5 @@ render() == 'Hello'); } @@ -17,12 +17,12 @@ class ViewTest extends \PHPUnit\Framework\TestCase */ public function testInvalidView() { - new View('dogs', __DIR__ . '/data/view/'); + new View('dogs', ROOT_DIR . 'tests/data/View/'); } public function testViewVars() { - $view = new View('vars', __DIR__ . '/data/view/'); + $view = new View('vars', ROOT_DIR . 'tests/data/View/'); $view->who = 'World'; self::assertTrue(isset($view->who)); From 3b700f8d3c5d6c4ab881b16cbcf03718db133c66 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 21:33:35 +0700 Subject: [PATCH 13/28] Refactored project structure (Improvements). --- bootstrap.php | 7 +------ src/Application.php | 2 +- tests/bootstrap.php | 7 ++----- tests/src/Plugin/EmailTest.php | 8 +------- tests/src/Plugin/Util/PhpUnitResultTest.php | 4 ---- 5 files changed, 5 insertions(+), 23 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 2bb67d62..d554db01 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -26,12 +26,7 @@ if (!defined('RUNTIME_DIR')) { require_once(ROOT_DIR . 'vendor/autoload.php'); -// Load configuration if present: -$conf = []; -$conf['b8']['app']['namespace'] = 'PHPCensor'; -$conf['b8']['app']['default_controller'] = 'Home'; - -$config = new PHPCensor\Config($conf); +$config = new PHPCensor\Config(); $configFile = APP_DIR . 'config.yml'; if (file_exists($configFile)) { diff --git a/src/Application.php b/src/Application.php index 857cc17b..8a56716e 100644 --- a/src/Application.php +++ b/src/Application.php @@ -281,7 +281,7 @@ class Application $namespace = $this->toPhpName($route['namespace']); $controller = $this->toPhpName($route['controller']); - return $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller'; + return 'PHPCensor\\' . $namespace . '\\' . $controller . 'Controller'; } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0783ef40..89b44ec2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -26,11 +26,8 @@ if (!defined('RUNTIME_DIR')) { require_once(ROOT_DIR . 'vendor/autoload.php'); -$conf = []; - -$conf['b8']['app']['namespace'] = 'PHPCensor'; -$conf['b8']['app']['default_controller'] = 'Home'; -$conf['php-censor']['url'] = 'http://php-censor.local'; +$conf = []; +$conf['php-censor']['url'] = 'http://php-censor.local'; $config = new PHPCensor\Config($conf); diff --git a/tests/src/Plugin/EmailTest.php b/tests/src/Plugin/EmailTest.php index 315424c1..6d2ff213 100644 --- a/tests/src/Plugin/EmailTest.php +++ b/tests/src/Plugin/EmailTest.php @@ -56,13 +56,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase $this->mailDelivered = true; $self = $this; - $config = new Config([ - 'b8' => [ - 'view' => [ - 'path' => SRC_DIR . 'View/' - ] - ] - ]); + new Config(); $this->mockProject = $this ->getMockBuilder('\PHPCensor\Model\Project') diff --git a/tests/src/Plugin/Util/PhpUnitResultTest.php b/tests/src/Plugin/Util/PhpUnitResultTest.php index d16bde0c..0587effd 100644 --- a/tests/src/Plugin/Util/PhpUnitResultTest.php +++ b/tests/src/Plugin/Util/PhpUnitResultTest.php @@ -48,8 +48,6 @@ class PhpUnitResultTest extends \PHPUnit\Framework\TestCase self::assertContains('Incomplete Test:', $output[5]['message']); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; - } catch (\PHPUnit\Framework\ExpectationFailedException $e) { - self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; } self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']); @@ -57,8 +55,6 @@ class PhpUnitResultTest extends \PHPUnit\Framework\TestCase self::assertContains('Skipped Test:', $output[11]['message']); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; - } catch (\PHPUnit\Framework\ExpectationFailedException $e) { - self::$skipped[] = ['cls' => $resultClass, 'ex' => $e]; } } From a16c82babcefd2f103a0e9140d0977397fbedfb7 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 4 Mar 2018 23:42:14 +0700 Subject: [PATCH 14/28] Code style fixes (and -> &&). --- src/Controller/HomeController.php | 4 +++- src/Controller/WebhookController.php | 8 ++++---- src/Store/BuildStore.php | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index dba36bc8..63fc94dd 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -31,7 +31,9 @@ class HomeController extends Controller ], ]); foreach($widgets_config as $name => $params) { - $side = (isset($params['side']) and ($params['side'] == 'right')) ? 'right' : 'left'; + $side = (isset($params['side']) && 'right' === $params['side']) + ? 'right' + : 'left'; $widgets[$side][$name] = $params; } diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index 3501e4e0..faacfc08 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -664,17 +664,17 @@ class WebhookController extends Controller $activeStates = ['open']; $inactiveStates = ['closed']; - if (!in_array($action, $activeActions) and !in_array($action, $inactiveActions)) { + if (!in_array($action, $activeActions) && !in_array($action, $inactiveActions)) { return ['status' => 'ignored', 'message' => 'Action ' . $action . ' ignored']; } - if (!in_array($state, $activeStates) and !in_array($state, $inactiveStates)) { + if (!in_array($state, $activeStates) && !in_array($state, $inactiveStates)) { return ['status' => 'ignored', 'message' => 'State ' . $state . ' ignored']; } $envs = []; // Get environment form labels - if (in_array($action, $activeActions) and in_array($state, $activeStates)) { + if (in_array($action, $activeActions) && in_array($state, $activeStates)) { if (isset($pullRequest['labels']) && is_array($pullRequest['labels'])) { foreach ($pullRequest['labels'] as $label) { if (strpos($label['name'], 'env:') === 0) { @@ -708,7 +708,7 @@ class WebhookController extends Controller } } - if (($state == 'closed') and $pullRequest['merged']) { + if ('closed' === $state && $pullRequest['merged']) { // update base branch environments $environmentNames = $project->getEnvironmentsNamesByBranch($pullRequest['base_branch']); $envsUpdated = array_merge($envsUpdated, $environmentNames); diff --git a/src/Store/BuildStore.php b/src/Store/BuildStore.php index 9e15613d..898d7434 100644 --- a/src/Store/BuildStore.php +++ b/src/Store/BuildStore.php @@ -298,13 +298,13 @@ class BuildStore extends Store } $latest[] = $build; } - if (empty($projects[$project_id][$environment]['success']) and ($item['status'] == Build::STATUS_SUCCESS)) { + if (empty($projects[$project_id][$environment]['success']) && Build::STATUS_SUCCESS === $item['status']) { if (is_null($build)) { $build = new Build($item); } $projects[$project_id][$environment]['success'] = $build; } - if (empty($projects[$project_id][$environment]['failed']) and ($item['status'] == Build::STATUS_FAILED)) { + if (empty($projects[$project_id][$environment]['failed']) && Build::STATUS_FAILED === $item['status']) { if (is_null($build)) { $build = new Build($item); } From 50b117455ee81cb7adf6a5643e23eeeeb04f2b6e Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 5 Mar 2018 19:32:49 +0700 Subject: [PATCH 15/28] Code style fixes. --- src/Command/RebuildQueueCommand.php | 2 +- src/Controller/BuildController.php | 4 +- src/Controller/BuildStatusController.php | 2 +- src/Controller/HomeController.php | 8 +- src/Controller/SessionController.php | 8 +- src/Controller/UserController.php | 4 +- src/Controller/WebhookController.php | 66 +++++++-------- .../WidgetBuildErrorsController.php | 6 +- src/Helper/Bitbucket.php | 2 +- src/Helper/BuildInterpolator.php | 84 +++++++++---------- src/Helper/CommandExecutor.php | 2 +- src/Helper/Github.php | 4 +- src/Helper/Lang.php | 19 +++-- src/Http/Router.php | 4 +- src/Logging/BuildDBLogHandler.php | 8 +- src/Logging/Handler.php | 34 ++++---- src/Model/Build/GithubBuild.php | 2 +- src/Model/Build/GitlabBuild.php | 4 +- 18 files changed, 133 insertions(+), 130 deletions(-) diff --git a/src/Command/RebuildQueueCommand.php b/src/Command/RebuildQueueCommand.php index e43f6720..e5e3cf44 100644 --- a/src/Command/RebuildQueueCommand.php +++ b/src/Command/RebuildQueueCommand.php @@ -55,7 +55,7 @@ class RebuildQueueCommand extends Command ); } - $store = Factory::getStore('Build'); + $store = Factory::getStore('Build'); $result = $store->getByStatus(0); $this->logger->addInfo(sprintf('Found %d builds', count($result['items']))); diff --git a/src/Controller/BuildController.php b/src/Controller/BuildController.php index 7aea2daa..de6ed610 100644 --- a/src/Controller/BuildController.php +++ b/src/Controller/BuildController.php @@ -119,10 +119,10 @@ class BuildController extends Controller break; } - $rebuild = Lang::get('rebuild_now'); + $rebuild = Lang::get('rebuild_now'); $rebuildLink = APP_URL . 'build/rebuild/' . $build->getId(); - $delete = Lang::get('delete_build'); + $delete = Lang::get('delete_build'); $deleteLink = APP_URL . 'build/delete/' . $build->getId(); $project = Factory::getStore('Project')->getByPrimaryKey($build->getProjectId()); diff --git a/src/Controller/BuildStatusController.php b/src/Controller/BuildStatusController.php index f6c6901a..23d376f9 100644 --- a/src/Controller/BuildStatusController.php +++ b/src/Controller/BuildStatusController.php @@ -82,7 +82,7 @@ class BuildStatusController extends Controller { /* @var Project $project */ $project = $this->projectStore->getById($projectId); - $xml = new \SimpleXMLElement(''); + $xml = new \SimpleXMLElement(''); if (!$project instanceof Project || !$project->getAllowPublicStatus()) { return $this->renderXml($xml); diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 63fc94dd..2ee3dca8 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -19,10 +19,11 @@ class HomeController extends Controller $this->layout->title = Lang::get('dashboard'); $widgets = [ - 'left' => [], + 'left' => [], 'right' => [], ]; - $widgets_config = Config::getInstance()->get('php-censor.dashboard_widgets', [ + + $widgetsConfig = Config::getInstance()->get('php-censor.dashboard_widgets', [ 'all_projects' => [ 'side' => 'left', ], @@ -30,7 +31,8 @@ class HomeController extends Controller 'side' => 'right', ], ]); - foreach($widgets_config as $name => $params) { + + foreach($widgetsConfig as $name => $params) { $side = (isset($params['side']) && 'right' === $params['side']) ? 'right' : 'left'; diff --git a/src/Controller/SessionController.php b/src/Controller/SessionController.php index 106f4a9c..66b7ef12 100644 --- a/src/Controller/SessionController.php +++ b/src/Controller/SessionController.php @@ -189,17 +189,15 @@ class SessionController extends Controller { if ($this->request->getMethod() == 'POST') { $email = $this->getParam('email', null); - $user = $this->userStore->getByEmail($email); + $user = $this->userStore->getByEmail($email); if (empty($user)) { $this->view->error = Lang::get('reset_no_user_exists'); return $this->view->render(); } - $key = md5(date('Y-m-d') . $user->getHash()); - $url = APP_URL; - - $message = Lang::get('reset_email_body', $user->getName(), $url, $user->getId(), $key); + $key = md5(date('Y-m-d') . $user->getHash()); + $message = Lang::get('reset_email_body', $user->getName(), APP_URL, $user->getId(), $key); $email = new Email(); $email->setEmailTo($user->getEmail(), $user->getName()); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 3e8b5ab4..5bd8ac26 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -197,7 +197,7 @@ class UserController extends Controller $this->requireAdmin(); $method = $this->request->getMethod(); - $user = $this->userStore->getById($userId); + $user = $this->userStore->getById($userId); if (empty($user)) { throw new NotFoundException(Lang::get('user_n_not_found', $userId)); @@ -291,7 +291,7 @@ class UserController extends Controller { $this->requireAdmin(); - $user = $this->userStore->getById($userId); + $user = $this->userStore->getById($userId); if (empty($user)) { throw new NotFoundException(Lang::get('user_n_not_found', $userId)); diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index faacfc08..e2a2602d 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -423,10 +423,10 @@ class WebhookController extends Controller $url = $payload['pull_request']['commits_url']; //for large pull requests, allow grabbing more then the default number of commits - $custom_per_page = Config::getInstance()->get('php-censor.github.per_page'); - $params = []; - if ($custom_per_page) { - $params['per_page'] = $custom_per_page; + $customPerPage = Config::getInstance()->get('php-censor.github.per_page'); + $params = []; + if ($customPerPage) { + $params['per_page'] = $customPerPage; } $client = new Client(); @@ -490,12 +490,12 @@ class WebhookController extends Controller $project = $this->fetchProject($projectId, ['gitlab', 'git']); $payloadString = file_get_contents("php://input"); - $payload = json_decode($payloadString, true); + $payload = json_decode($payloadString, true); // build on merge request events if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { $attributes = $payload['object_attributes']; - if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { + if ($attributes['state'] === 'opened' || $attributes['state'] === 'reopened') { $branch = $attributes['source_branch']; $commit = $attributes['last_commit']; $committer = $commit['author']['email']; @@ -520,8 +520,8 @@ class WebhookController extends Controller $status = 'failed'; foreach ($payload['commits'] as $commit) { try { - $branch = str_replace('refs/heads/', '', $payload['ref']); - $committer = $commit['author']['email']; + $branch = str_replace('refs/heads/', '', $payload['ref']); + $committer = $commit['author']['email']; $results[$commit['id']] = $this->createBuild( Build::SOURCE_WEBHOOK, $project, @@ -554,11 +554,11 @@ class WebhookController extends Controller */ public function svn($projectId) { - $project = $this->fetchProject($projectId, 'svn'); - $branch = $this->getParam('branch', $project->getBranch()); - $commit = $this->getParam('commit'); + $project = $this->fetchProject($projectId, 'svn'); + $branch = $this->getParam('branch', $project->getBranch()); + $commit = $this->getParam('commit'); $commitMessage = $this->getParam('message'); - $committer = $this->getParam('committer'); + $committer = $this->getParam('committer'); return $this->createBuild( Build::SOURCE_WEBHOOK, @@ -770,13 +770,13 @@ class WebhookController extends Controller // Check if a build already exists for this commit ID: $builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId); - $ignore_environments = []; - $ignore_tags = []; + $ignoreEnvironments = []; + $ignoreTags = []; if ($builds['count']) { foreach($builds['items'] as $build) { /** @var Build $build */ - $ignore_environments[$build->getId()] = $build->getEnvironment(); - $ignore_tags[$build->getId()] = $build->getTag(); + $ignoreEnvironments[$build->getId()] = $build->getEnvironment(); + $ignoreTags[$build->getId()] = $build->getTag(); } } @@ -790,20 +790,20 @@ class WebhookController extends Controller $environments = $project->getEnvironmentsObjects(); if ($environments['count']) { - $created_builds = []; - $environment_names = $project->getEnvironmentsNamesByBranch($branch); + $createdBuilds = []; + $environmentNames = $project->getEnvironmentsNamesByBranch($branch); // use base branch from project - if (!empty($environment_names)) { + if (!empty($environmentNames)) { $duplicates = []; - foreach ($environment_names as $environment_name) { + foreach ($environmentNames as $environmentName) { if ( - !in_array($environment_name, $ignore_environments) || - ($tag && !in_array($tag, $ignore_tags, true)) + !in_array($environmentName, $ignoreEnvironments) || + ($tag && !in_array($tag, $ignoreTags, true)) ) { // If not, create a new build job for it: $build = $this->buildService->createBuild( $project, - $environment_name, + $environmentName, $commitId, $project->getBranch(), $tag, @@ -814,19 +814,19 @@ class WebhookController extends Controller $extra ); - $created_builds[] = [ + $createdBuilds[] = [ 'id' => $build->getID(), - 'environment' => $environment_name, + 'environment' => $environmentName, ]; } else { - $duplicates[] = array_search($environment_name, $ignore_environments); + $duplicates[] = array_search($environmentName, $ignoreEnvironments); } } - if (!empty($created_builds)) { + if (!empty($createdBuilds)) { if (empty($duplicates)) { - return ['status' => 'ok', 'builds' => $created_builds]; + return ['status' => 'ok', 'builds' => $createdBuilds]; } else { - return ['status' => 'ok', 'builds' => $created_builds, 'message' => sprintf('For this commit some builds already exists (%s)', implode(', ', $duplicates))]; + return ['status' => 'ok', 'builds' => $createdBuilds, 'message' => sprintf('For this commit some builds already exists (%s)', implode(', ', $duplicates))]; } } else { return ['status' => 'ignored', 'message' => sprintf('For this commit already created builds (%s)', implode(', ', $duplicates))]; @@ -835,10 +835,10 @@ class WebhookController extends Controller return ['status' => 'ignored', 'message' => 'Branch not assigned to any environment']; } } else { - $environment_name = null; + $environmentName = null; if ( - !in_array($environment_name, $ignore_environments, true) || - ($tag && !in_array($tag, $ignore_tags, true)) + !in_array($environmentName, $ignoreEnvironments, true) || + ($tag && !in_array($tag, $ignoreTags, true)) ) { $build = $this->buildService->createBuild( $project, @@ -857,7 +857,7 @@ class WebhookController extends Controller } else { return [ 'status' => 'ignored', - 'message' => sprintf('Duplicate of build #%d', array_search($environment_name, $ignore_environments)), + 'message' => sprintf('Duplicate of build #%d', array_search($environmentName, $ignoreEnvironments)), ]; } } diff --git a/src/Controller/WidgetBuildErrorsController.php b/src/Controller/WidgetBuildErrorsController.php index 779500a9..81bf2c33 100644 --- a/src/Controller/WidgetBuildErrorsController.php +++ b/src/Controller/WidgetBuildErrorsController.php @@ -72,15 +72,15 @@ class WidgetBuildErrorsController extends Controller $view->builds = $builds['projects']; $projects = $this->projectStore->getByIds(array_keys($builds['projects'])); - $view_projects = []; + $viewProjects = []; foreach($projects as $id => $project) { if (!$project->getArchived()) { - $view_projects[$id] = $project; + $viewProjects[$id] = $project; } else { unset($builds['projects'][$id]); } } - $view->projects = $view_projects; + $view->projects = $viewProjects; } else { $view = new View('WidgetBuildErrors/empty'); } diff --git a/src/Helper/Bitbucket.php b/src/Helper/Bitbucket.php index 36f869f1..524d2112 100644 --- a/src/Helper/Bitbucket.php +++ b/src/Helper/Bitbucket.php @@ -92,7 +92,7 @@ class Bitbucket */ public function getPullRequestDiff($repo, $pullRequestId) { - $username = Config::getInstance()->get('php-censor.bitbucket.username'); + $username = Config::getInstance()->get('php-censor.bitbucket.username'); $appPassword = Config::getInstance()->get('php-censor.bitbucket.app_password'); if (empty($username) || empty($appPassword)) { diff --git a/src/Helper/BuildInterpolator.php b/src/Helper/BuildInterpolator.php index f6458051..f113bad0 100644 --- a/src/Helper/BuildInterpolator.php +++ b/src/Helper/BuildInterpolator.php @@ -6,7 +6,7 @@ use PHPCensor\Model\Build as BaseBuild; /** * The BuildInterpolator class replaces variables in a string with build-specific information. - * + * * @package PHPCensor\Helper */ class BuildInterpolator @@ -17,7 +17,7 @@ class BuildInterpolator * @var mixed[] * @see setupInterpolationVars() */ - protected $interpolation_vars = []; + protected $interpolationVars = []; /** * Sets the variables that will be used for interpolation. @@ -28,46 +28,46 @@ class BuildInterpolator */ public function setupInterpolationVars(BaseBuild $build, $buildPath, $url) { - $this->interpolation_vars = []; - $this->interpolation_vars['%PHPCI%'] = 1; - $this->interpolation_vars['%COMMIT%'] = $build->getCommitId(); - $this->interpolation_vars['%SHORT_COMMIT%'] = substr($build->getCommitId(), 0, 7); - $this->interpolation_vars['%COMMIT_EMAIL%'] = $build->getCommitterEmail(); - $this->interpolation_vars['%COMMIT_MESSAGE%'] = $build->getCommitMessage(); - $this->interpolation_vars['%COMMIT_URI%'] = $build->getCommitLink(); - $this->interpolation_vars['%BRANCH%'] = $build->getBranch(); - $this->interpolation_vars['%BRANCH_URI%'] = $build->getBranchLink(); - $this->interpolation_vars['%ENVIRONMENT%'] = $build->getEnvironment(); - $this->interpolation_vars['%PROJECT%'] = $build->getProjectId(); - $this->interpolation_vars['%BUILD%'] = $build->getId(); - $this->interpolation_vars['%PROJECT_TITLE%'] = $build->getProjectTitle(); - $this->interpolation_vars['%PROJECT_URI%'] = $url . "project/view/" . $build->getProjectId(); - $this->interpolation_vars['%BUILD_PATH%'] = $buildPath; - $this->interpolation_vars['%BUILD_URI%'] = $url . "build/view/" . $build->getId(); - $this->interpolation_vars['%PHPCI_COMMIT%'] = $this->interpolation_vars['%COMMIT%']; - $this->interpolation_vars['%PHPCI_SHORT_COMMIT%'] = $this->interpolation_vars['%SHORT_COMMIT%']; - $this->interpolation_vars['%PHPCI_COMMIT_MESSAGE%'] = $this->interpolation_vars['%COMMIT_MESSAGE%']; - $this->interpolation_vars['%PHPCI_COMMIT_EMAIL%'] = $this->interpolation_vars['%COMMIT_EMAIL%']; - $this->interpolation_vars['%PHPCI_COMMIT_URI%'] = $this->interpolation_vars['%COMMIT_URI%']; - $this->interpolation_vars['%PHPCI_PROJECT%'] = $this->interpolation_vars['%PROJECT%']; - $this->interpolation_vars['%PHPCI_BUILD%'] = $this->interpolation_vars['%BUILD%']; - $this->interpolation_vars['%PHPCI_PROJECT_TITLE%'] = $this->interpolation_vars['%PROJECT_TITLE%']; - $this->interpolation_vars['%PHPCI_PROJECT_URI%'] = $this->interpolation_vars['%PROJECT_URI%']; - $this->interpolation_vars['%PHPCI_BUILD_PATH%'] = $this->interpolation_vars['%BUILD_PATH%']; - $this->interpolation_vars['%PHPCI_BUILD_URI%'] = $this->interpolation_vars['%BUILD_URI%']; + $this->interpolationVars = []; + $this->interpolationVars['%PHPCI%'] = 1; + $this->interpolationVars['%COMMIT%'] = $build->getCommitId(); + $this->interpolationVars['%SHORT_COMMIT%'] = substr($build->getCommitId(), 0, 7); + $this->interpolationVars['%COMMIT_EMAIL%'] = $build->getCommitterEmail(); + $this->interpolationVars['%COMMIT_MESSAGE%'] = $build->getCommitMessage(); + $this->interpolationVars['%COMMIT_URI%'] = $build->getCommitLink(); + $this->interpolationVars['%BRANCH%'] = $build->getBranch(); + $this->interpolationVars['%BRANCH_URI%'] = $build->getBranchLink(); + $this->interpolationVars['%ENVIRONMENT%'] = $build->getEnvironment(); + $this->interpolationVars['%PROJECT%'] = $build->getProjectId(); + $this->interpolationVars['%BUILD%'] = $build->getId(); + $this->interpolationVars['%PROJECT_TITLE%'] = $build->getProjectTitle(); + $this->interpolationVars['%PROJECT_URI%'] = $url . "project/view/" . $build->getProjectId(); + $this->interpolationVars['%BUILD_PATH%'] = $buildPath; + $this->interpolationVars['%BUILD_URI%'] = $url . "build/view/" . $build->getId(); + $this->interpolationVars['%PHPCI_COMMIT%'] = $this->interpolationVars['%COMMIT%']; + $this->interpolationVars['%PHPCI_SHORT_COMMIT%'] = $this->interpolationVars['%SHORT_COMMIT%']; + $this->interpolationVars['%PHPCI_COMMIT_MESSAGE%'] = $this->interpolationVars['%COMMIT_MESSAGE%']; + $this->interpolationVars['%PHPCI_COMMIT_EMAIL%'] = $this->interpolationVars['%COMMIT_EMAIL%']; + $this->interpolationVars['%PHPCI_COMMIT_URI%'] = $this->interpolationVars['%COMMIT_URI%']; + $this->interpolationVars['%PHPCI_PROJECT%'] = $this->interpolationVars['%PROJECT%']; + $this->interpolationVars['%PHPCI_BUILD%'] = $this->interpolationVars['%BUILD%']; + $this->interpolationVars['%PHPCI_PROJECT_TITLE%'] = $this->interpolationVars['%PROJECT_TITLE%']; + $this->interpolationVars['%PHPCI_PROJECT_URI%'] = $this->interpolationVars['%PROJECT_URI%']; + $this->interpolationVars['%PHPCI_BUILD_PATH%'] = $this->interpolationVars['%BUILD_PATH%']; + $this->interpolationVars['%PHPCI_BUILD_URI%'] = $this->interpolationVars['%BUILD_URI%']; putenv('PHPCI=1'); - putenv('PHPCI_COMMIT=' . $this->interpolation_vars['%COMMIT%']); - putenv('PHPCI_SHORT_COMMIT=' . $this->interpolation_vars['%SHORT_COMMIT%']); - putenv('PHPCI_COMMIT_MESSAGE=' . $this->interpolation_vars['%COMMIT_MESSAGE%']); - putenv('PHPCI_COMMIT_EMAIL=' . $this->interpolation_vars['%COMMIT_EMAIL%']); - putenv('PHPCI_COMMIT_URI=' . $this->interpolation_vars['%COMMIT_URI%']); - putenv('PHPCI_PROJECT=' . $this->interpolation_vars['%PROJECT%']); - putenv('PHPCI_BUILD=' . $this->interpolation_vars['%BUILD%']); - putenv('PHPCI_PROJECT_TITLE=' . $this->interpolation_vars['%PROJECT_TITLE%']); - putenv('PHPCI_BUILD_PATH=' . $this->interpolation_vars['%BUILD_PATH%']); - putenv('PHPCI_BUILD_URI=' . $this->interpolation_vars['%BUILD_URI%']); - putenv('PHPCI_ENVIRONMENT=' . $this->interpolation_vars['%ENVIRONMENT%']); + putenv('PHPCI_COMMIT=' . $this->interpolationVars['%COMMIT%']); + putenv('PHPCI_SHORT_COMMIT=' . $this->interpolationVars['%SHORT_COMMIT%']); + putenv('PHPCI_COMMIT_MESSAGE=' . $this->interpolationVars['%COMMIT_MESSAGE%']); + putenv('PHPCI_COMMIT_EMAIL=' . $this->interpolationVars['%COMMIT_EMAIL%']); + putenv('PHPCI_COMMIT_URI=' . $this->interpolationVars['%COMMIT_URI%']); + putenv('PHPCI_PROJECT=' . $this->interpolationVars['%PROJECT%']); + putenv('PHPCI_BUILD=' . $this->interpolationVars['%BUILD%']); + putenv('PHPCI_PROJECT_TITLE=' . $this->interpolationVars['%PROJECT_TITLE%']); + putenv('PHPCI_BUILD_PATH=' . $this->interpolationVars['%BUILD_PATH%']); + putenv('PHPCI_BUILD_URI=' . $this->interpolationVars['%BUILD_URI%']); + putenv('PHPCI_ENVIRONMENT=' . $this->interpolationVars['%ENVIRONMENT%']); } /** @@ -78,8 +78,8 @@ class BuildInterpolator */ public function interpolate($input) { - $keys = array_keys($this->interpolation_vars); - $values = array_values($this->interpolation_vars); + $keys = array_keys($this->interpolationVars); + $values = array_values($this->interpolationVars); return str_replace($keys, $values, $input); } } diff --git a/src/Helper/CommandExecutor.php b/src/Helper/CommandExecutor.php index 31ccb6b9..597b2055 100644 --- a/src/Helper/CommandExecutor.php +++ b/src/Helper/CommandExecutor.php @@ -61,7 +61,7 @@ class CommandExecutor implements CommandExecutorInterface * @param bool $quiet * @param bool $verbose */ - public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false) + public function __construct(BuildLogger $logger, $rootDir, $quiet = false, $verbose = false) { $this->logger = $logger; $this->quiet = $quiet; diff --git a/src/Helper/Github.php b/src/Helper/Github.php index 1bcc041b..6c89ae9c 100644 --- a/src/Helper/Github.php +++ b/src/Helper/Github.php @@ -34,9 +34,9 @@ class Github $results[] = $item; } - foreach ($headers as $header_name => $header) { + foreach ($headers as $headerName => $header) { if ( - 'Link' === $header_name && + 'Link' === $headerName && preg_match('/^<([^>]+)>; rel="next"/', implode(', ', $header), $r) ) { $host = parse_url($r[1]); diff --git a/src/Helper/Lang.php b/src/Helper/Lang.php index 831ac9d0..63bd7d24 100644 --- a/src/Helper/Lang.php +++ b/src/Helper/Lang.php @@ -31,7 +31,7 @@ class Lang /** * @var array */ - protected static $default_strings = []; + protected static $defaultStrings = []; /** * Get a specific string from the language file. @@ -46,8 +46,8 @@ class Lang if (array_key_exists($string, self::$strings)) { $params[0] = self::$strings[$string]; return call_user_func_array('sprintf', $params); - } elseif (self::DEFAULT_LANGUAGE !== self::$language && array_key_exists($string, self::$default_strings)) { - $params[0] = self::$default_strings[$string]; + } elseif (self::DEFAULT_LANGUAGE !== self::$language && array_key_exists($string, self::$defaultStrings)) { + $params[0] = self::$defaultStrings[$string]; return call_user_func_array('sprintf', $params); } @@ -124,14 +124,14 @@ class Lang * Initialise the Language helper, try load the language file for the user's browser or the configured default. * * @param Config $config - * @param string $language_force + * @param string $languageForce */ - public static function init(Config $config, $language_force = null) + public static function init(Config $config, $languageForce = null) { - self::$default_strings = self::loadLanguage(self::DEFAULT_LANGUAGE); + self::$defaultStrings = self::loadLanguage(self::DEFAULT_LANGUAGE); self::loadAvailableLanguages(); - if ($language_force && self::setLanguage($language_force)) { + if ($languageForce && self::setLanguage($languageForce)) { return; } @@ -165,7 +165,10 @@ class Lang */ protected static function loadLanguage($language = null) { - $language = $language ? $language : self::$language; + $language = $language + ? $language + : self::$language; + $langFile = SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php'; if (!file_exists($langFile)) { diff --git a/src/Http/Router.php b/src/Http/Router.php index db80d271..471cac94 100644 --- a/src/Http/Router.php +++ b/src/Http/Router.php @@ -62,9 +62,9 @@ class Router //------- // Set up default values for everything: //------- - $thisNamespace = 'Controller'; + $thisNamespace = 'Controller'; $thisController = null; - $thisAction = null; + $thisAction = null; if (array_key_exists('namespace', $route['defaults'])) { $thisNamespace = $route['defaults']['namespace']; diff --git a/src/Logging/BuildDBLogHandler.php b/src/Logging/BuildDBLogHandler.php index 80edadd0..6a325c61 100644 --- a/src/Logging/BuildDBLogHandler.php +++ b/src/Logging/BuildDBLogHandler.php @@ -22,12 +22,12 @@ class BuildDBLogHandler extends AbstractProcessingHandler /** * @var int last flush timestamp */ - protected $flush_timestamp = 0; + protected $flushTimestamp = 0; /** * @var int flush delay, seconds */ - protected $flush_delay = 1; + protected $flushDelay = 1; /** * @param Build $build @@ -60,7 +60,7 @@ class BuildDBLogHandler extends AbstractProcessingHandler { $this->build->setLog($this->logValue); Factory::getStore('Build')->save($this->build); - $this->flush_timestamp = time(); + $this->flushTimestamp = time(); } /** @@ -74,7 +74,7 @@ class BuildDBLogHandler extends AbstractProcessingHandler $this->logValue .= $message . PHP_EOL; - if ($this->flush_timestamp < (time() - $this->flush_delay)) { + if ($this->flushTimestamp < (time() - $this->flushDelay)) { $this->flushData(); } } diff --git a/src/Logging/Handler.php b/src/Logging/Handler.php index e2ec1925..3c63f801 100644 --- a/src/Logging/Handler.php +++ b/src/Logging/Handler.php @@ -62,10 +62,10 @@ class Handler public function handleError($level, $message, $file, $line) { if (error_reporting() & $level) { - $exception_level = isset($this->levels[$level]) ? $this->levels[$level] : $level; + $exceptionLevel = isset($this->levels[$level]) ? $this->levels[$level] : $level; throw new \ErrorException( - sprintf('%s: %s in %s line %d', $exception_level, $message, $file, $line), + sprintf('%s: %s in %s line %d', $exceptionLevel, $message, $file, $line), 0, $level, $file, @@ -79,22 +79,22 @@ class Handler */ public function handleFatalError() { - $fatal_error = error_get_last(); + $fatalError = error_get_last(); try { if (($error = error_get_last()) !== null) { $error = new \ErrorException( sprintf( '%s: %s in %s line %d', - $fatal_error['type'], - $fatal_error['message'], - $fatal_error['file'], - $fatal_error['line'] + $fatalError['type'], + $fatalError['message'], + $fatalError['file'], + $fatalError['line'] ), 0, - $fatal_error['type'], - $fatal_error['file'], - $fatal_error['line'] + $fatalError['type'], + $fatalError['file'], + $fatalError['line'] ); $this->log($error); } @@ -102,15 +102,15 @@ class Handler $error = new \ErrorException( sprintf( '%s: %s in %s line %d', - $fatal_error['type'], - $fatal_error['message'], - $fatal_error['file'], - $fatal_error['line'] + $fatalError['type'], + $fatalError['message'], + $fatalError['file'], + $fatalError['line'] ), 0, - $fatal_error['type'], - $fatal_error['file'], - $fatal_error['line'] + $fatalError['type'], + $fatalError['file'], + $fatalError['line'] ); $this->log($error); } diff --git a/src/Model/Build/GithubBuild.php b/src/Model/Build/GithubBuild.php index 52fcaf9f..778d11d9 100644 --- a/src/Model/Build/GithubBuild.php +++ b/src/Model/Build/GithubBuild.php @@ -161,7 +161,7 @@ class GithubBuild extends GitBuild $project = $this->getProject(); if (!is_null($project)) { - $reference = $project->getReference(); + $reference = $project->getReference(); $commitLink = '
#$1'; $rtn = preg_replace('/\#([0-9]+)/', $commitLink, $rtn); $rtn = preg_replace('/\@([a-zA-Z0-9_]+)/', '@$1', $rtn); diff --git a/src/Model/Build/GitlabBuild.php b/src/Model/Build/GitlabBuild.php index ad5a30b9..56252e75 100644 --- a/src/Model/Build/GitlabBuild.php +++ b/src/Model/Build/GitlabBuild.php @@ -49,9 +49,9 @@ class GitlabBuild extends GitBuild $key = trim($this->getProject()->getSshPrivateKey()); if (!empty($key)) { - $user = $this->getProject()->getAccessInformation("user"); + $user = $this->getProject()->getAccessInformation("user"); $domain = $this->getProject()->getAccessInformation("domain"); - $port = $this->getProject()->getAccessInformation('port'); + $port = $this->getProject()->getAccessInformation('port'); $url = $user . '@' . $domain . ':'; From d5333b2b80a7583875131a0fcc96850d1b58e046 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 6 Mar 2018 20:14:37 +0700 Subject: [PATCH 16/28] Code style fixes. --- src/Controller/WebhookController.php | 38 ++++++++++++++++++++-------- src/Plugin/FlowdockNotify.php | 2 +- src/Plugin/Mysql.php | 6 +++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index e2a2602d..7ffe654e 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -65,10 +65,11 @@ class WebhookController extends Controller $this->buildService = new BuildService($this->buildStore); } - /** Handle the action, Ensuring to return a JsonResponse. + /** + * Handle the action, Ensuring to return a JsonResponse. * * @param string $action - * @param mixed $actionParams + * @param array $actionParams * * @return Response */ @@ -91,6 +92,10 @@ class WebhookController extends Controller /** * Called by Bitbucket. + * + * @param integer $projectId + * + * @return array */ public function bitbucket($projectId) { @@ -124,7 +129,7 @@ class WebhookController extends Controller * Handle the payload when Bitbucket sends a commit webhook. * * @param Project $project - * @param array $payload + * @param array $payload * * @return array */ @@ -176,7 +181,7 @@ class WebhookController extends Controller return ['status' => 'ok']; } - $username = Config::getInstance()->get('php-censor.bitbucket.username'); + $username = Config::getInstance()->get('php-censor.bitbucket.username'); $appPassword = Config::getInstance()->get('php-censor.bitbucket.app_password'); if (empty($username) || empty($appPassword)) { @@ -185,7 +190,7 @@ class WebhookController extends Controller $commitsUrl = $payload['pullrequest']['links']['commits']['href']; - $client = new Client(); + $client = new Client(); $commitsResponse = $client->get($commitsUrl, [ 'auth' => [$username, $appPassword], ]); @@ -244,11 +249,14 @@ class WebhookController extends Controller /** * Bitbucket POST service. + * + * @param array $payload + * @param Project $project + * + * @return array */ - protected function bitbucketService($payload, $project) + protected function bitbucketService(array $payload, Project $project) { - $payload = json_decode($this->getParam('payload'), true); - $results = []; $status = 'failed'; foreach ($payload['commits'] as $commit) { @@ -303,6 +311,10 @@ class WebhookController extends Controller /** * Called by Github Webhooks: + * + * @param integer $projectId + * + * @return array */ public function github($projectId) { @@ -340,7 +352,7 @@ class WebhookController extends Controller * Handle the payload when Github sends a commit webhook. * * @param Project $project - * @param array $payload + * @param array $payload * * @return array */ @@ -484,6 +496,10 @@ class WebhookController extends Controller /** * Called by Gitlab Webhooks: + * + * @param integer $projectId + * + * @return array */ public function gitlab($projectId) { @@ -866,8 +882,8 @@ class WebhookController extends Controller /** * Fetch a project and check its type. * - * @param int|string $projectId id or title of project - * @param array|string $expectedType + * @param integer $projectId id or title of project + * @param string $expectedType * * @return Project * diff --git a/src/Plugin/FlowdockNotify.php b/src/Plugin/FlowdockNotify.php index b33ca08b..bc69d255 100644 --- a/src/Plugin/FlowdockNotify.php +++ b/src/Plugin/FlowdockNotify.php @@ -56,7 +56,7 @@ class FlowdockNotify extends Plugin $message = $this->builder->interpolate($this->message); $successfulBuild = $this->build->isSuccessful() ? 'Success' : 'Failed'; $push = new Push($this->apiKey); - $flowMessage = TeamInboxMessage::create() + $flowMessage = TeamInboxMessage::create() ->setSource("PHPCensor") ->setFromAddress($this->email) ->setFromName($this->build->getProject()->getTitle()) diff --git a/src/Plugin/Mysql.php b/src/Plugin/Mysql.php index 02f36cef..ad64deaa 100644 --- a/src/Plugin/Mysql.php +++ b/src/Plugin/Mysql.php @@ -100,11 +100,13 @@ class Mysql extends Plugin } /** - * @param string $query + * @param array $query + * * @return boolean + * * @throws \Exception */ - protected function executeFile($query) + protected function executeFile(array $query) { if (!isset($query['file'])) { throw new \Exception('Import statement must contain a \'file\' key'); From ba11827340cc8a9362d9d163917fdf21bcaaccb2 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 8 Mar 2018 10:31:31 +0700 Subject: [PATCH 17/28] Code style fixes (DIRECTORY_SEPARATOR -> '/'). --- src/Controller/BuildController.php | 2 +- src/Helper/CommandExecutor.php | 8 ++++---- src/Helper/Lang.php | 6 +++--- src/Model/Build.php | 2 +- src/Plugin/Atoum.php | 4 ++-- src/Plugin/Composer.php | 4 ++-- src/Plugin/Grunt.php | 8 ++++---- src/Plugin/Gulp.php | 8 ++++---- src/Plugin/Lint.php | 8 ++++++-- src/Plugin/Pdepend.php | 6 +++--- src/Plugin/Phar.php | 4 ++-- src/Plugin/Phing.php | 4 ++-- src/Plugin/PhpCpd.php | 4 ++-- src/Plugin/PhpLoc.php | 6 +++--- src/Plugin/PhpTalLint.php | 10 +++++----- src/Plugin/SecurityChecker.php | 4 ++-- src/Plugin/Xmpp.php | 8 ++++---- 17 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/Controller/BuildController.php b/src/Controller/BuildController.php index de6ed610..20176c38 100644 --- a/src/Controller/BuildController.php +++ b/src/Controller/BuildController.php @@ -146,7 +146,7 @@ class BuildController extends Controller protected function getUiPlugins() { $rtn = []; - $path = PUBLIC_DIR . 'assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'build-plugins' . DIRECTORY_SEPARATOR; + $path = PUBLIC_DIR . 'assets/js/build-plugins/'; $dir = opendir($path); while ($item = readdir($dir)) { diff --git a/src/Helper/CommandExecutor.php b/src/Helper/CommandExecutor.php index 597b2055..cbbd4243 100644 --- a/src/Helper/CommandExecutor.php +++ b/src/Helper/CommandExecutor.php @@ -335,14 +335,14 @@ class CommandExecutor implements CommandExecutorInterface public function getComposerBinDir($path) { if (is_dir($path)) { - $composer = $path . DIRECTORY_SEPARATOR . 'composer.json'; + $composer = $path . '/composer.json'; if (is_file($composer)) { $json = json_decode(file_get_contents($composer)); if (isset($json->config->{"bin-dir"})) { - return $path . DIRECTORY_SEPARATOR . $json->config->{"bin-dir"}; - } elseif (is_dir($path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin')) { - return $path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin'; + return $path . '/' . $json->config->{"bin-dir"}; + } elseif (is_dir($path . '/vendor/bin')) { + return $path . '/vendor/bin'; } } } diff --git a/src/Helper/Lang.php b/src/Helper/Lang.php index 63bd7d24..57964d85 100644 --- a/src/Helper/Lang.php +++ b/src/Helper/Lang.php @@ -101,7 +101,7 @@ class Lang { $languages = []; foreach (self::$languages as $language) { - $strings = include(SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php'); + $strings = include(SRC_DIR . 'Languages/lang.' . $language . '.php'); $languages[$language] = !empty($strings['language_name']) ? $strings['language_name'] . ' (' . $language . ')' : $language; @@ -169,7 +169,7 @@ class Lang ? $language : self::$language; - $langFile = SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php'; + $langFile = SRC_DIR . 'Languages/lang.' . $language . '.php'; if (!file_exists($langFile)) { return null; @@ -189,7 +189,7 @@ class Lang protected static function loadAvailableLanguages() { $matches = []; - foreach (glob(SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.*.php') as $file) { + foreach (glob(SRC_DIR . 'Languages/lang.*.php') as $file) { if (preg_match('/lang\.([a-z]{2}\-?[a-z]*)\.php/', $file, $matches)) { self::$languages[] = $matches[1]; } diff --git a/src/Model/Build.php b/src/Model/Build.php index 6551668e..21e5dc95 100644 --- a/src/Model/Build.php +++ b/src/Model/Build.php @@ -790,7 +790,7 @@ class Build extends Model */ protected function getZeroConfigPlugins(Builder $builder) { - $pluginDir = SRC_DIR . 'Plugin' . DIRECTORY_SEPARATOR; + $pluginDir = SRC_DIR . 'Plugin/'; $dir = new \DirectoryIterator($pluginDir); $config = [ diff --git a/src/Plugin/Atoum.php b/src/Plugin/Atoum.php index f62424b4..cd6a7b30 100644 --- a/src/Plugin/Atoum.php +++ b/src/Plugin/Atoum.php @@ -47,7 +47,7 @@ class Atoum extends Plugin parent::__construct($builder, $build, $options); if (isset($options['executable'])) { - $this->executable = $this->builder->buildPath . DIRECTORY_SEPARATOR.$options['executable']; + $this->executable = $this->builder->buildPath . '/' . $options['executable']; } else { $this->executable = $this->findBinary('atoum'); } @@ -83,7 +83,7 @@ class Atoum extends Plugin } if ($this->directory !== null) { - $dirPath = $this->builder->buildPath . DIRECTORY_SEPARATOR . $this->directory; + $dirPath = $this->builder->buildPath . '/' . $this->directory; $cmd .= " -d '{$dirPath}'"; } diff --git a/src/Plugin/Composer.php b/src/Plugin/Composer.php index aa68f87f..093ca94c 100644 --- a/src/Plugin/Composer.php +++ b/src/Plugin/Composer.php @@ -46,7 +46,7 @@ class Composer extends Plugin implements ZeroConfigPluginInterface $this->ignorePlatformReqs = false; if (array_key_exists('directory', $options)) { - $this->directory = $path . DIRECTORY_SEPARATOR . $options['directory']; + $this->directory = $path . '/' . $options['directory']; } if (array_key_exists('action', $options)) { @@ -80,7 +80,7 @@ class Composer extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - $path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json'; + $path = $builder->buildPath . '/composer.json'; if (file_exists($path) && $stage == Build::STAGE_SETUP) { return true; diff --git a/src/Plugin/Grunt.php b/src/Plugin/Grunt.php index e5db5e24..cb6afb0e 100644 --- a/src/Plugin/Grunt.php +++ b/src/Plugin/Grunt.php @@ -8,7 +8,7 @@ use PHPCensor\Plugin; /** * Grunt Plugin - Provides access to grunt functionality. - * + * * @author Tobias Tom */ class Grunt extends Plugin @@ -26,14 +26,14 @@ class Grunt extends Plugin { return 'grunt'; } - + /** * {@inheritdoc} */ public function __construct(Builder $builder, Build $build, array $options = []) { parent::__construct($builder, $build, $options); - + $path = $this->builder->buildPath; $this->directory = $path; $this->task = null; @@ -42,7 +42,7 @@ class Grunt extends Plugin // Handle options: if (isset($options['directory'])) { - $this->directory = $path . DIRECTORY_SEPARATOR . $options['directory']; + $this->directory = $path . '/' . $options['directory']; } if (isset($options['task'])) { diff --git a/src/Plugin/Gulp.php b/src/Plugin/Gulp.php index 6c28cea9..3d65433b 100644 --- a/src/Plugin/Gulp.php +++ b/src/Plugin/Gulp.php @@ -8,7 +8,7 @@ use PHPCensor\Plugin; /** * Gulp Plugin - Provides access to gulp functionality. - * + * * @author Dirk Heilig */ class Gulp extends Plugin @@ -26,14 +26,14 @@ class Gulp extends Plugin { return 'gulp'; } - + /** * {@inheritdoc} */ public function __construct(Builder $builder, Build $build, array $options = []) { parent::__construct($builder, $build, $options); - + $path = $this->builder->buildPath; $this->directory = $path; $this->task = null; @@ -42,7 +42,7 @@ class Gulp extends Plugin // Handle options: if (isset($options['directory'])) { - $this->directory = $path . DIRECTORY_SEPARATOR . $options['directory']; + $this->directory = $path . '/' . $options['directory']; } if (isset($options['task'])) { diff --git a/src/Plugin/Lint.php b/src/Plugin/Lint.php index 9ef07967..35623383 100644 --- a/src/Plugin/Lint.php +++ b/src/Plugin/Lint.php @@ -9,7 +9,7 @@ use PHPCensor\Plugin; /** * PHP Lint Plugin - Provides access to PHP lint functionality. - * + * * @author Dan Cryer */ class Lint extends Plugin @@ -83,7 +83,11 @@ class Lint extends Plugin if ($item->isFile() && $item->getExtension() == 'php' && !$this->lintFile($php, $itemPath)) { $success = false; - } elseif ($item->isDir() && $this->recursive && !$this->lintDirectory($php, $itemPath . DIRECTORY_SEPARATOR)) { + } elseif ( + $item->isDir() && + $this->recursive && + !$this->lintDirectory($php, ($itemPath . '/')) + ) { $success = false; } diff --git a/src/Plugin/Pdepend.php b/src/Plugin/Pdepend.php index 39445e47..c4ce4f5a 100644 --- a/src/Plugin/Pdepend.php +++ b/src/Plugin/Pdepend.php @@ -122,9 +122,9 @@ class Pdepend extends Plugin $success = $this->builder->executeCommand( $cmd, - $this->buildLocation . DIRECTORY_SEPARATOR . $this->summary, - $this->buildLocation . DIRECTORY_SEPARATOR . $this->chart, - $this->buildLocation . DIRECTORY_SEPARATOR . $this->pyramid, + $this->buildLocation . '/' . $this->summary, + $this->buildLocation . '/' . $this->chart, + $this->buildLocation . '/' . $this->pyramid, $ignore, $this->directory ); diff --git a/src/Plugin/Phar.php b/src/Plugin/Phar.php index b43b95ec..0b39d477 100644 --- a/src/Plugin/Phar.php +++ b/src/Plugin/Phar.php @@ -178,7 +178,7 @@ class Phar extends Plugin $content = ''; $filename = $this->getStub(); if ($filename) { - $content = file_get_contents($this->builder->buildPath . DIRECTORY_SEPARATOR . $this->getStub()); + $content = file_get_contents($this->builder->buildPath . '/' . $this->getStub()); } return $content; } @@ -192,7 +192,7 @@ class Phar extends Plugin $success = false; try { - $file = $this->getDirectory() . DIRECTORY_SEPARATOR . $this->getFilename(); + $file = $this->getDirectory() . '/' . $this->getFilename(); $phar = new PHPPhar($file, 0, $this->getFilename()); $phar->buildFromDirectory($this->builder->buildPath, $this->getRegExp()); diff --git a/src/Plugin/Phing.php b/src/Plugin/Phing.php index 5edda716..aac615d3 100644 --- a/src/Plugin/Phing.php +++ b/src/Plugin/Phing.php @@ -38,7 +38,7 @@ class Phing extends Plugin * Set working directory */ if (isset($options['directory'])) { - $directory = $this->builder->buildPath . DIRECTORY_SEPARATOR . $options['directory']; + $directory = $this->builder->buildPath . '/' . $options['directory']; } else { $directory = $this->builder->buildPath; } @@ -228,7 +228,7 @@ class Phing extends Plugin */ public function setPropertyFile($propertyFile) { - if (!file_exists($this->getDirectory() . DIRECTORY_SEPARATOR . $propertyFile)) { + if (!file_exists($this->getDirectory() . '/' . $propertyFile)) { throw new \Exception('Specified property file does not exist.'); } diff --git a/src/Plugin/PhpCpd.php b/src/Plugin/PhpCpd.php index 4094d164..e4189856 100644 --- a/src/Plugin/PhpCpd.php +++ b/src/Plugin/PhpCpd.php @@ -83,8 +83,8 @@ class PhpCpd extends Plugin implements ZeroConfigPluginInterface $namesExclude = ' --names-exclude '; foreach ($this->ignore as $item) { - $item = rtrim($item, DIRECTORY_SEPARATOR); - if (is_file(rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $item)) { + $item = rtrim($item, '/'); + if (is_file(rtrim($this->path, '/') . '/' . $item)) { $ignoredFile = explode('/', $item); $filesToIgnore[] = array_pop($ignoredFile); } else { diff --git a/src/Plugin/PhpLoc.php b/src/Plugin/PhpLoc.php index 597514a8..6ff7898f 100644 --- a/src/Plugin/PhpLoc.php +++ b/src/Plugin/PhpLoc.php @@ -10,7 +10,7 @@ use PHPCensor\ZeroConfigPluginInterface; /** * PHP Loc - Allows PHP Copy / Lines of Code testing. - * + * * @author Johan van der Heide */ class PhpLoc extends Plugin implements ZeroConfigPluginInterface @@ -27,7 +27,7 @@ class PhpLoc extends Plugin implements ZeroConfigPluginInterface { return 'php_loc'; } - + /** * Check if this plugin can be executed. * @param $stage @@ -67,7 +67,7 @@ class PhpLoc extends Plugin implements ZeroConfigPluginInterface if (count($this->builder->ignore)) { $map = function ($item) { - return ' --exclude ' . rtrim($item, DIRECTORY_SEPARATOR); + return ' --exclude ' . rtrim($item, '/'); }; $ignore = array_map($map, $this->builder->ignore); diff --git a/src/Plugin/PhpTalLint.php b/src/Plugin/PhpTalLint.php index 1f2c784d..cc77b056 100644 --- a/src/Plugin/PhpTalLint.php +++ b/src/Plugin/PhpTalLint.php @@ -127,7 +127,7 @@ class PhpTalLint extends Plugin if (!$this->lintFile($itemPath)) { $success = false; } - } elseif ($item->isDir() && $this->recursive && !$this->lintDirectory($itemPath . DIRECTORY_SEPARATOR)) { + } elseif ($item->isDir() && $this->recursive && !$this->lintDirectory($itemPath . '/')) { $success = false; } @@ -174,10 +174,10 @@ class PhpTalLint extends Plugin list($suffixes, $tales) = $this->getFlags(); - $lint = __DIR__ . DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; - $lint .= 'vendor' . DIRECTORY_SEPARATOR . 'phptal' . DIRECTORY_SEPARATOR . 'phptal' . DIRECTORY_SEPARATOR; - $lint .= 'tools' . DIRECTORY_SEPARATOR . 'phptal_lint.php'; - $cmd = '/usr/bin/env php ' . $lint . ' %s %s "%s"'; + $lint = __DIR__ . '/'; + $lint .= 'vendor/phptal/phptal/'; + $lint .= 'tools/phptal_lint.php'; + $cmd = 'php ' . $lint . ' %s %s "%s"'; $this->builder->executeCommand($cmd, $suffixes, $tales, $this->builder->buildPath . $path); diff --git a/src/Plugin/SecurityChecker.php b/src/Plugin/SecurityChecker.php index ba665f87..9634531d 100644 --- a/src/Plugin/SecurityChecker.php +++ b/src/Plugin/SecurityChecker.php @@ -59,7 +59,7 @@ class SecurityChecker extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - $path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.lock'; + $path = $builder->buildPath . '/composer.lock'; if (file_exists($path) && $stage == Build::STAGE_TEST) { return true; @@ -72,7 +72,7 @@ class SecurityChecker extends Plugin implements ZeroConfigPluginInterface { $success = true; $checker = new BaseSecurityChecker(); - $warnings = $checker->check($this->builder->buildPath . DIRECTORY_SEPARATOR . 'composer.lock'); + $warnings = $checker->check($this->builder->buildPath . '/composer.lock'); if ($warnings) { foreach ($warnings as $library => $warning) { diff --git a/src/Plugin/Xmpp.php b/src/Plugin/Xmpp.php index 4c6aa8cd..8d6c62b0 100644 --- a/src/Plugin/Xmpp.php +++ b/src/Plugin/Xmpp.php @@ -111,8 +111,8 @@ class XMPP extends Plugin */ public function findConfigFile() { - if (file_exists($this->builder->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc')) { - if (md5(file_get_contents($this->builder->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc')) + if (file_exists($this->builder->buildPath . '/.sendxmpprc')) { + if (md5(file_get_contents($this->builder->buildPath . '/.sendxmpprc')) !== md5($this->getConfigFormat())) { return null; } @@ -140,7 +140,7 @@ class XMPP extends Plugin /* * Try to build conf file */ - $config_file = $this->builder->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc'; + $config_file = $this->builder->buildPath . '/.sendxmpprc'; if (is_null($this->findConfigFile())) { file_put_contents($config_file, $this->getConfigFormat()); chmod($config_file, 0600); @@ -154,7 +154,7 @@ class XMPP extends Plugin $tls = ' -t'; } - $message_file = $this->builder->buildPath . DIRECTORY_SEPARATOR . uniqid('xmppmessage'); + $message_file = $this->builder->buildPath . '/' . uniqid('xmppmessage'); if ($this->buildMessage($message_file) === false) { return false; } From 4013fc76ffa61fcb07da819a2dc4df8d1e933cc8 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 8 Mar 2018 10:33:29 +0700 Subject: [PATCH 18/28] Fixes after rebase. --- src/Plugin/Option/PhpUnitOptions.php | 2 +- src/Plugin/Pdepend.php | 2 +- src/Plugin/PhpUnit.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Plugin/Option/PhpUnitOptions.php b/src/Plugin/Option/PhpUnitOptions.php index 0a49869d..0789f12f 100644 --- a/src/Plugin/Option/PhpUnitOptions.php +++ b/src/Plugin/Option/PhpUnitOptions.php @@ -2,7 +2,7 @@ namespace PHPCensor\Plugin\Option; -use b8\Config; +use PHPCensor\Config; /** * Class PhpUnitOptions validates and parse the option for the PhpUnitV2 plugin diff --git a/src/Plugin/Pdepend.php b/src/Plugin/Pdepend.php index c4ce4f5a..e267a260 100644 --- a/src/Plugin/Pdepend.php +++ b/src/Plugin/Pdepend.php @@ -2,7 +2,7 @@ namespace PHPCensor\Plugin; -use b8\Config; +use PHPCensor\Config; use PHPCensor\Builder; use PHPCensor\Model\Build; use PHPCensor\Plugin; diff --git a/src/Plugin/PhpUnit.php b/src/Plugin/PhpUnit.php index 3ce1b052..3f61f7f0 100644 --- a/src/Plugin/PhpUnit.php +++ b/src/Plugin/PhpUnit.php @@ -2,7 +2,7 @@ namespace PHPCensor\Plugin; -use b8\Config; +use PHPCensor\Config; use PHPCensor; use PHPCensor\Builder; use PHPCensor\Model\Build; From 8d9c4824c7d66f690346058d5728d5d5de942eaf Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 8 Mar 2018 10:54:52 +0700 Subject: [PATCH 19/28] Code style fixes (camelCased variables). --- src/Application.php | 4 +- src/Builder.php | 13 ++-- src/Config.php | 28 ++++----- src/Controller/GroupController.php | 6 +- src/Database.php | 6 +- src/Model/Build.php | 26 ++++---- src/Model/Project.php | 62 +++++++++---------- src/Plugin/Behat.php | 6 +- src/Plugin/Mysql.php | 10 +-- src/Plugin/PhpSpec.php | 4 +- src/Plugin/PhpTalLint.php | 12 ++-- .../Util/TestResultParsers/Codeception.php | 44 ++++++------- src/Plugin/Xmpp.php | 20 +++--- src/Store.php | 12 ++-- src/Store/BuildStore.php | 30 ++++----- 15 files changed, 141 insertions(+), 142 deletions(-) diff --git a/src/Application.php b/src/Application.php index 8a56716e..3855e815 100644 --- a/src/Application.php +++ b/src/Application.php @@ -221,8 +221,8 @@ class Application $groups[] = $thisGroup; } - $archived_projects = Factory::getStore('Project')->getAll(true); - $layout->archived_projects = $archived_projects['items']; + $archivedProjects = Factory::getStore('Project')->getAll(true); + $layout->archived_projects = $archivedProjects['items']; $layout->groups = $groups; } diff --git a/src/Builder.php b/src/Builder.php index 64b476f9..20b33003 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -195,12 +195,11 @@ class Builder implements LoggerAwareInterface $this->build->sendStatusPostback(); $success = true; - $previous_build = $this->build->getProject()->getPreviousBuild($this->build->getBranch()); + $previousBuild = $this->build->getProject()->getPreviousBuild($this->build->getBranch()); + $previousState = Build::STATUS_PENDING; - $previous_state = Build::STATUS_PENDING; - - if ($previous_build) { - $previous_state = $previous_build->getStatus(); + if ($previousBuild) { + $previousState = $previousBuild->getStatus(); } try { @@ -232,13 +231,13 @@ class Builder implements LoggerAwareInterface if ($success) { $this->pluginExecutor->executePlugins($this->config, Build::STAGE_SUCCESS); - if ($previous_state == Build::STATUS_FAILED) { + if ($previousState == Build::STATUS_FAILED) { $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FIXED); } } else { $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FAILURE); - if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_PENDING) { + if ($previousState == Build::STATUS_SUCCESS || $previousState == Build::STATUS_PENDING) { $this->pluginExecutor->executePlugins($this->config, Build::STAGE_BROKEN); } } diff --git a/src/Config.php b/src/Config.php index 28ea9054..b1a9482c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -71,8 +71,8 @@ class Config $keyParts = explode('.', $key); $selected = $this->config; - $i = -1; - $last_part = count($keyParts) - 1; + $i = -1; + $lastPart = count($keyParts) - 1; while ($part = array_shift($keyParts)) { $i++; @@ -80,7 +80,7 @@ class Config return $default; } - if ($i === $last_part) { + if ($i === $lastPart) { return $selected[$part]; } else { $selected = $selected[$part]; @@ -177,25 +177,25 @@ class Config return; } - foreach ($target as $target_key => $target_value) { - if (isset($source[$target_key])) { - if (!is_array($source[$target_key]) && !is_array($target_value)) { + foreach ($target as $targetKey => $targetValue) { + if (isset($source[$targetKey])) { + if (!is_array($source[$targetKey]) && !is_array($targetValue)) { // Neither value is an array, overwrite - $source[$target_key] = $target_value; - } elseif (is_array($source[$target_key]) && is_array($target_value)) { + $source[$targetKey] = $targetValue; + } elseif (is_array($source[$targetKey]) && is_array($targetValue)) { // Both are arrays, deep merge them - self::deepMerge($source[$target_key], $target_value); - } elseif (is_array($source[$target_key])) { + self::deepMerge($source[$targetKey], $targetValue); + } elseif (is_array($source[$targetKey])) { // Source is the array, push target value - $source[$target_key][] = $target_value; + $source[$targetKey][] = $targetValue; } else { // Target is the array, push source value and copy back - $target_value[] = $source[$target_key]; - $source[$target_key] = $target_value; + $targetValue[] = $source[$targetKey]; + $source[$targetKey] = $targetValue; } } else { // No merge required, just set the value - $source[$target_key] = $target_value; + $source[$targetKey] = $targetValue; } } } diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index 8b703120..56744723 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -45,10 +45,10 @@ class GroupController extends Controller 'title' => $group->getTitle(), 'id' => $group->getId(), ]; - $projects_active = Factory::getStore('Project')->getByGroupId($group->getId(), false); - $projects_archived = Factory::getStore('Project')->getByGroupId($group->getId(), true); + $projectsActive = Factory::getStore('Project')->getByGroupId($group->getId(), false); + $projectsArchived = Factory::getStore('Project')->getByGroupId($group->getId(), true); - $thisGroup['projects'] = array_merge($projects_active['items'], $projects_archived['items']); + $thisGroup['projects'] = array_merge($projectsActive['items'], $projectsArchived['items']); $groups[] = $thisGroup; } diff --git a/src/Database.php b/src/Database.php index 9091f8bb..2be2993e 100644 --- a/src/Database.php +++ b/src/Database.php @@ -192,12 +192,12 @@ class Database extends \PDO /** * @param string $statement - * @param array $driver_options + * @param array $driverOptions * * @return \PDOStatement */ - public function prepareCommon($statement, array $driver_options = []) + public function prepareCommon($statement, array $driverOptions = []) { - return parent::prepare($this->quoteNames($statement), $driver_options); + return parent::prepare($this->quoteNames($statement), $driverOptions); } } diff --git a/src/Model/Build.php b/src/Model/Build.php index 21e5dc95..fb2b1b66 100644 --- a/src/Model/Build.php +++ b/src/Model/Build.php @@ -756,27 +756,27 @@ class Build extends Model */ protected function handleConfig(Builder $builder, $buildPath) { - $build_config = $this->getProject()->getBuildConfig(); + $buildConfig = $this->getProject()->getBuildConfig(); - if (empty($build_config)) { + if (empty($buildConfig)) { if (file_exists($buildPath . '/.php-censor.yml')) { - $build_config = file_get_contents($buildPath . '/.php-censor.yml'); + $buildConfig = file_get_contents($buildPath . '/.php-censor.yml'); } elseif (file_exists($buildPath . '/.phpci.yml')) { - $build_config = file_get_contents($buildPath . '/.phpci.yml'); + $buildConfig = file_get_contents($buildPath . '/.phpci.yml'); } elseif (file_exists($buildPath . '/phpci.yml')) { - $build_config = file_get_contents($buildPath . '/phpci.yml'); + $buildConfig = file_get_contents($buildPath . '/phpci.yml'); } else { - $build_config = $this->getZeroConfigPlugins($builder); + $buildConfig = $this->getZeroConfigPlugins($builder); } } // for YAML configs from files/DB - if (is_string($build_config)) { + if (is_string($buildConfig)) { $yamlParser = new YamlParser(); - $build_config = $yamlParser->parse($build_config); + $buildConfig = $yamlParser->parse($buildConfig); } - $builder->setConfigArray($build_config); + $builder->setConfigArray($buildConfig); return true; } @@ -989,11 +989,11 @@ class Build extends Model $end = new \DateTime(); } - $diff = date_diff($start, $end); + $diff = date_diff($start, $end); $parts = []; - foreach (['y', 'm', 'd', 'h', 'i', 's'] as $time_part) { - if ($diff->{$time_part} != 0) { - $parts[] = $diff->{$time_part} . ($time_part == 'i' ? 'm' : $time_part); + foreach (['y', 'm', 'd', 'h', 'i', 's'] as $timePart) { + if ($diff->{$timePart} != 0) { + $parts[] = $diff->{$timePart} . ($timePart == 'i' ? 'm' : $timePart); } } diff --git a/src/Model/Project.php b/src/Model/Project.php index 56e6ec9d..e6ccfacb 100644 --- a/src/Model/Project.php +++ b/src/Model/Project.php @@ -702,14 +702,14 @@ class Project extends Model */ public function getEnvironmentsNames() { - $environments = $this->getEnvironmentsObjects(); - $environments_names = []; + $environments = $this->getEnvironmentsObjects(); + $environmentsNames = []; foreach($environments['items'] as $environment) { /** @var Environment $environment */ - $environments_names[] = $environment->getName(); + $environmentsNames[] = $environment->getName(); } - return $environments_names; + return $environmentsNames; } /** @@ -719,15 +719,15 @@ class Project extends Model */ public function getEnvironments() { - $environments = $this->getEnvironmentsObjects(); - $environments_config = []; + $environments = $this->getEnvironmentsObjects(); + $environmentsConfig = []; foreach($environments['items'] as $environment) { /** @var Environment $environment */ - $environments_config[$environment->getName()] = $environment->getBranches(); + $environmentsConfig[$environment->getName()] = $environment->getBranches(); } - $yaml_dumper = new YamlDumper(); - $value = $yaml_dumper->dump($environments_config, 10, 0, true, false); + $yamlDumper = new YamlDumper(); + $value = $yamlDumper->dump($environmentsConfig, 10, 0, true, false); return $value; } @@ -739,18 +739,18 @@ class Project extends Model */ public function setEnvironments($value) { - $yaml_parser = new YamlParser(); - $environments_config = $yaml_parser->parse($value); - $environments_names = !empty($environments_config) ? array_keys($environments_config) : []; - $current_environments = $this->getEnvironmentsObjects(); - $store = $this->getEnvironmentStore(); - foreach ($current_environments['items'] as $environment) { + $yamlParser = new YamlParser(); + $environmentsConfig = $yamlParser->parse($value); + $environmentsNames = !empty($environmentsConfig) ? array_keys($environmentsConfig) : []; + $currentEnvironments = $this->getEnvironmentsObjects(); + $store = $this->getEnvironmentStore(); + foreach ($currentEnvironments['items'] as $environment) { /** @var Environment $environment */ - $key = array_search($environment->getName(), $environments_names); + $key = array_search($environment->getName(), $environmentsNames); if ($key !== false) { // already exist - unset($environments_names[$key]); - $environment->setBranches(!empty($environments_config[$environment->getName()]) ? $environments_config[$environment->getName()] : []); + unset($environmentsNames[$key]); + $environment->setBranches(!empty($environmentsConfig[$environment->getName()]) ? $environmentsConfig[$environment->getName()] : []); $store->save($environment); } else { // remove @@ -758,13 +758,13 @@ class Project extends Model } } - if (!empty($environments_names)) { + if (!empty($environmentsNames)) { // add - foreach ($environments_names as $environment_name) { + foreach ($environmentsNames as $environmentName) { $environment = new Environment(); $environment->setProjectId($this->getId()); - $environment->setName($environment_name); - $environment->setBranches(!empty($environments_config[$environment->getName()]) ? $environments_config[$environment->getName()] : []); + $environment->setName($environmentName); + $environment->setBranches(!empty($environmentsConfig[$environment->getName()]) ? $environmentsConfig[$environment->getName()] : []); $store->save($environment); } } @@ -777,31 +777,31 @@ class Project extends Model */ public function getEnvironmentsNamesByBranch($branch) { - $environments_names = []; - $environments = $this->getEnvironmentsObjects(); - $default_branch = ($branch == $this->getBranch()); + $environmentsNames = []; + $environments = $this->getEnvironmentsObjects(); + $defaultBranch = ($branch == $this->getBranch()); foreach($environments['items'] as $environment) { /** @var Environment $environment */ - if ($default_branch || in_array($branch, $environment->getBranches())) { - $environments_names[] = $environment->getName(); + if ($defaultBranch || in_array($branch, $environment->getBranches())) { + $environmentsNames[] = $environment->getName(); } } - return $environments_names; + return $environmentsNames; } /** - * @param string $environment_name + * @param string $environmentName * * @return string[] */ - public function getBranchesByEnvironment($environment_name) + public function getBranchesByEnvironment($environmentName) { $branches = []; $environments = $this->getEnvironmentsObjects(); foreach($environments['items'] as $environment) { /** @var Environment $environment */ - if ($environment_name == $environment->getName()) { + if ($environmentName == $environment->getName()) { return $environment->getBranches(); } } diff --git a/src/Plugin/Behat.php b/src/Plugin/Behat.php index c47be480..1825e1b5 100644 --- a/src/Plugin/Behat.php +++ b/src/Plugin/Behat.php @@ -9,7 +9,7 @@ use PHPCensor\Plugin; /** * Behat BDD Plugin - * + * * @author Dan Cryer */ class Behat extends Plugin @@ -50,7 +50,7 @@ class Behat extends Plugin */ public function execute() { - $current_dir = getcwd(); + $currentDir = getcwd(); chdir($this->builder->buildPath); $behat = $this->executable; @@ -62,7 +62,7 @@ class Behat extends Plugin } $success = $this->builder->executeCommand($behat . ' %s', $this->features); - chdir($current_dir); + chdir($currentDir); list($errorCount, $data) = $this->parseBehatOutput(); diff --git a/src/Plugin/Mysql.php b/src/Plugin/Mysql.php index ad64deaa..1205aac7 100644 --- a/src/Plugin/Mysql.php +++ b/src/Plugin/Mysql.php @@ -130,26 +130,26 @@ class Mysql extends Plugin /** * Builds the MySQL import command required to import/execute the specified file * - * @param string $import_file Path to file, relative to the build root - * @param string $database If specified, this database is selected before execution + * @param string $importFile Path to file, relative to the build root + * @param string $database If specified, this database is selected before execution * * @return string */ - protected function getImportCommand($import_file, $database = null) + protected function getImportCommand($importFile, $database = null) { $decompression = [ 'bz2' => '| bzip2 --decompress', 'gz' => '| gzip --decompress', ]; - $extension = strtolower(pathinfo($import_file, PATHINFO_EXTENSION)); + $extension = strtolower(pathinfo($importFile, PATHINFO_EXTENSION)); $decompressionCmd = ''; if (array_key_exists($extension, $decompression)) { $decompressionCmd = $decompression[$extension]; } $args = [ - ':import_file' => escapeshellarg($import_file), + ':import_file' => escapeshellarg($importFile), ':decomp_cmd' => $decompressionCmd, ':host' => escapeshellarg($this->host), ':user' => escapeshellarg($this->user), diff --git a/src/Plugin/PhpSpec.php b/src/Plugin/PhpSpec.php index 063235aa..3ce247dc 100644 --- a/src/Plugin/PhpSpec.php +++ b/src/Plugin/PhpSpec.php @@ -97,8 +97,8 @@ class PhpSpec extends Plugin $error['message'] = (String)$attr['message']; } - foreach ($child->xpath('system-err') as $system_err) { - $error['raw'] = (String)$system_err; + foreach ($child->xpath('system-err') as $systemError) { + $error['raw'] = (String)$systemError; } $case['error'] = $error; diff --git a/src/Plugin/PhpTalLint.php b/src/Plugin/PhpTalLint.php index cc77b056..1206c6a9 100644 --- a/src/Plugin/PhpTalLint.php +++ b/src/Plugin/PhpTalLint.php @@ -35,12 +35,12 @@ class PhpTalLint extends Plugin /** * @var int */ - protected $allowed_warnings; + protected $allowedWarnings; /** * @var int */ - protected $allowed_errors; + protected $allowedErrors; /** * @var array The results of the lint scan @@ -58,8 +58,8 @@ class PhpTalLint extends Plugin $this->suffixes = ['zpt']; $this->ignore = $this->builder->ignore; - $this->allowed_warnings = 0; - $this->allowed_errors = 0; + $this->allowedWarnings = 0; + $this->allowedErrors = 0; if (!empty($options['directory'])) { $this->directories = [$options['directory']]; @@ -102,11 +102,11 @@ class PhpTalLint extends Plugin $success = true; - if ($this->allowed_warnings != -1 && $warnings > $this->allowed_warnings) { + if ($this->allowedWarnings != -1 && $warnings > $this->allowedWarnings) { $success = false; } - if ($this->allowed_errors != -1 && $errors > $this->allowed_errors) { + if ($this->allowedErrors != -1 && $errors > $this->allowedErrors) { $success = false; } diff --git a/src/Plugin/Util/TestResultParsers/Codeception.php b/src/Plugin/Util/TestResultParsers/Codeception.php index 6c2594a9..dfd97cae 100644 --- a/src/Plugin/Util/TestResultParsers/Codeception.php +++ b/src/Plugin/Util/TestResultParsers/Codeception.php @@ -39,39 +39,39 @@ class Codeception implements ParserInterface $this->results = new \SimpleXMLElement($this->resultsXml); // calculate total results - foreach ($this->results->testsuite as $test_suite) { - $this->totalTests += (int)$test_suite['tests']; - $this->totalTimeTaken += (float)$test_suite['time']; - $this->totalFailures += (int)$test_suite['failures']; - $this->totalErrors += (int)$test_suite['errors']; + foreach ($this->results->testsuite as $testSuite) { + $this->totalTests += (int)$testSuite['tests']; + $this->totalTimeTaken += (float)$testSuite['time']; + $this->totalFailures += (int)$testSuite['failures']; + $this->totalErrors += (int)$testSuite['errors']; - foreach ($test_suite->testcase as $test_case) { - $test_result = [ - 'suite' => (string)$test_suite['name'], - 'file' => str_replace($this->builder->buildPath, '/', (string) $test_case['file']), - 'name' => (string)$test_case['name'], - 'feature' => (string)$test_case['feature'], - 'assertions' => (int)$test_case['assertions'], - 'time' => (float)$test_case['time'] + foreach ($testSuite->testcase as $testCase) { + $testResult = [ + 'suite' => (string)$testSuite['name'], + 'file' => str_replace($this->builder->buildPath, '/', (string) $testCase['file']), + 'name' => (string)$testCase['name'], + 'feature' => (string)$testCase['feature'], + 'assertions' => (int)$testCase['assertions'], + 'time' => (float)$testCase['time'] ]; - if (isset($test_case['class'])) { - $test_result['class'] = (string) $test_case['class']; + if (isset($testCase['class'])) { + $testResult['class'] = (string) $testCase['class']; } // PHPUnit testcases does not have feature field. Use class::method instead - if (!$test_result['feature']) { - $test_result['feature'] = sprintf('%s::%s', $test_result['class'], $test_result['name']); + if (!$testResult['feature']) { + $testResult['feature'] = sprintf('%s::%s', $testResult['class'], $testResult['name']); } - if (isset($test_case->failure) || isset($test_case->error)) { - $test_result['pass'] = false; - $test_result['message'] = isset($test_case->failure) ? (string)$test_case->failure : (string)$test_case->error; + if (isset($testCase->failure) || isset($testCase->error)) { + $testResult['pass'] = false; + $testResult['message'] = isset($testCase->failure) ? (string)$testCase->failure : (string)$testCase->error; } else { - $test_result['pass'] = true; + $testResult['pass'] = true; } - $rtn[] = $test_result; + $rtn[] = $testResult; } } diff --git a/src/Plugin/Xmpp.php b/src/Plugin/Xmpp.php index 8d6c62b0..0c2b7d69 100644 --- a/src/Plugin/Xmpp.php +++ b/src/Plugin/Xmpp.php @@ -140,10 +140,10 @@ class XMPP extends Plugin /* * Try to build conf file */ - $config_file = $this->builder->buildPath . '/.sendxmpprc'; + $configFile = $this->builder->buildPath . '/.sendxmpprc'; if (is_null($this->findConfigFile())) { - file_put_contents($config_file, $this->getConfigFormat()); - chmod($config_file, 0600); + file_put_contents($configFile, $this->getConfigFormat()); + chmod($configFile, 0600); } /* @@ -154,8 +154,8 @@ class XMPP extends Plugin $tls = ' -t'; } - $message_file = $this->builder->buildPath . '/' . uniqid('xmppmessage'); - if ($this->buildMessage($message_file) === false) { + $messageFile = $this->builder->buildPath . '/' . uniqid('xmppmessage'); + if ($this->buildMessage($messageFile) === false) { return false; } @@ -165,23 +165,23 @@ class XMPP extends Plugin $cmd = $sendxmpp . "%s -f %s -m %s %s"; $recipients = implode(' ', $this->recipients); - $success = $this->builder->executeCommand($cmd, $tls, $config_file, $message_file, $recipients); + $success = $this->builder->executeCommand($cmd, $tls, $configFile, $messageFile, $recipients); print $this->builder->getLastOutput(); /* * Remove temp message file */ - $this->builder->executeCommand("rm -rf ".$message_file); + $this->builder->executeCommand("rm -rf ".$messageFile); return $success; } /** - * @param $message_file + * @param $messageFile * @return int */ - protected function buildMessage($message_file) + protected function buildMessage($messageFile) { if ($this->build->isSuccessful()) { $message = "✔ [".$this->build->getProjectTitle()."] Build #" . $this->build->getId()." successful"; @@ -191,6 +191,6 @@ class XMPP extends Plugin $message .= ' ('.strftime($this->dateFormat).')'; - return file_put_contents($message_file, $message); + return file_put_contents($messageFile, $message); } } diff --git a/src/Store.php b/src/Store.php index 53604050..ce218f92 100644 --- a/src/Store.php +++ b/src/Store.php @@ -144,19 +144,19 @@ abstract class Store $data = $obj->getDataArray(); $modified = ($saveAllColumns) ? array_keys($data) : $obj->getModified(); - $updates = []; - $update_params = []; + $updates = []; + $updateParams = []; foreach ($modified as $key) { - $updates[] = $key . ' = :' . $key; - $update_params[] = [$key, $data[$key]]; + $updates[] = $key . ' = :' . $key; + $updateParams[] = [$key, $data[$key]]; } if (count($updates)) { $qs = 'UPDATE {{' . $this->tableName . '}} SET ' . implode(', ', $updates) . ' WHERE {{' . $this->primaryKey . '}} = :primaryKey'; $q = Database::getConnection('write')->prepareCommon($qs); - foreach ($update_params as $update_param) { - $q->bindValue(':' . $update_param[0], $update_param[1]); + foreach ($updateParams as $updateParam) { + $q->bindValue(':' . $updateParam[0], $updateParam[1]); } $q->bindValue(':primaryKey', $data[$this->primaryKey]); diff --git a/src/Store/BuildStore.php b/src/Store/BuildStore.php index 898d7434..b06aa315 100644 --- a/src/Store/BuildStore.php +++ b/src/Store/BuildStore.php @@ -239,12 +239,12 @@ class BuildStore extends Store /** * Return an array of the latest builds for all projects. * - * @param integer $limit_by_project - * @param integer $limit_all + * @param integer $limitByProject + * @param integer $limitAll * * @return array */ - public function getAllProjectsLatestBuilds($limit_by_project = 5, $limit_all = 10) + public function getAllProjectsLatestBuilds($limitByProject = 5, $limitAll = 10) { // don't fetch log field - contain many data $query = ' @@ -275,40 +275,40 @@ class BuildStore extends Store $projects = []; $latest = []; foreach ($res as $item) { - $project_id = $item['project_id']; + $projectId = $item['project_id']; $environment = $item['environment']; - if (empty($projects[$project_id])) { - $projects[$project_id] = []; + if (empty($projects[$projectId])) { + $projects[$projectId] = []; } - if (empty($projects[$project_id][$environment])) { - $projects[$project_id][$environment] = [ + if (empty($projects[$projectId][$environment])) { + $projects[$projectId][$environment] = [ 'latest' => [], 'success' => null, 'failed' => null, ]; } $build = null; - if (count($projects[$project_id][$environment]['latest']) < $limit_by_project) { + if (count($projects[$projectId][$environment]['latest']) < $limitByProject) { $build = new Build($item); - $projects[$project_id][$environment]['latest'][] = $build; + $projects[$projectId][$environment]['latest'][] = $build; } - if (count($latest) < $limit_all) { + if (count($latest) < $limitAll) { if (is_null($build)) { $build = new Build($item); } $latest[] = $build; } - if (empty($projects[$project_id][$environment]['success']) && Build::STATUS_SUCCESS === $item['status']) { + if (empty($projects[$projectId][$environment]['success']) && Build::STATUS_SUCCESS === $item['status']) { if (is_null($build)) { $build = new Build($item); } - $projects[$project_id][$environment]['success'] = $build; + $projects[$projectId][$environment]['success'] = $build; } - if (empty($projects[$project_id][$environment]['failed']) && Build::STATUS_FAILED === $item['status']) { + if (empty($projects[$projectId][$environment]['failed']) && Build::STATUS_FAILED === $item['status']) { if (is_null($build)) { $build = new Build($item); } - $projects[$project_id][$environment]['failed'] = $build; + $projects[$projectId][$environment]['failed'] = $build; } } From 3783a9dea08f8051b1e9d1f847367dee6d819240 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 Mar 2018 18:15:38 +0700 Subject: [PATCH 20/28] Code style fixes (' '
  • - + getCommitterEmail()): ?>
    - +

    - getProject()->getTitle(); ?> + getProject()->getTitle(); ?> getStatus() == \PHPCensor\Model\Build::STATUS_PENDING): ?> getCreateDate()->format('H:i')); ?> @@ -27,4 +27,4 @@ use PHPCensor\Model\Build;

    getBranch()); ?>

    -
  • \ No newline at end of file + diff --git a/src/View/Build/view.phtml b/src/View/Build/view.phtml index da5f627a..edf57525 100644 --- a/src/View/Build/view.phtml +++ b/src/View/Build/view.phtml @@ -72,7 +72,7 @@ use PHPCensor\Model\BuildError; $branches = $build->getExtra('branches'); if (!empty($branches)) { foreach($branches as $branch) { - ?> - getCommitId(), 0, 7); ?> + getCommitId(), 0, 7); ?> @@ -113,14 +113,14 @@ use PHPCensor\Model\BuildError; - getCommitterEmail(); ?> + getCommitterEmail(); ?> - getCommitMessage(); ?> + getCommitMessage(); ?> @@ -175,26 +175,26 @@ use PHPCensor\Model\BuildError; @@ -38,7 +38,7 @@

    - +

    diff --git a/src/View/Session.phtml b/src/View/Session.phtml index 411c2958..ab7a5672 100644 --- a/src/View/Session.phtml +++ b/src/View/Session.phtml @@ -7,23 +7,23 @@ - - + +
    - +
    - - + + diff --git a/src/View/Session/forgotPassword.phtml b/src/View/Session/forgotPassword.phtml index 75e14508..b4303623 100644 --- a/src/View/Session/forgotPassword.phtml +++ b/src/View/Session/forgotPassword.phtml @@ -10,11 +10,11 @@
    - +
    -
    +
    diff --git a/src/View/Session/login.phtml b/src/View/Session/login.phtml index 4ff7451d..625ed519 100644 --- a/src/View/Session/login.phtml +++ b/src/View/Session/login.phtml @@ -2,8 +2,8 @@

    - + - + diff --git a/src/View/Session/resetPassword.phtml b/src/View/Session/resetPassword.phtml index ee693789..363c98be 100644 --- a/src/View/Session/resetPassword.phtml +++ b/src/View/Session/resetPassword.phtml @@ -5,7 +5,7 @@
    - +
    @@ -18,6 +18,6 @@
    - +
    diff --git a/src/View/User/edit.phtml b/src/View/User/edit.phtml index 96234e36..13e16c1a 100644 --- a/src/View/User/edit.phtml +++ b/src/View/User/edit.phtml @@ -2,7 +2,7 @@
    - +
    diff --git a/src/View/User/index.phtml b/src/View/User/index.phtml index 0c113a0e..17e6469a 100644 --- a/src/View/User/index.phtml +++ b/src/View/User/index.phtml @@ -7,7 +7,7 @@ $user = $this->getUser(); ?>
    - +
    @@ -40,19 +40,19 @@ $user = $this->getUser(); break; } ?> - - getEmail(); ?> - getName()); ?> - + + getEmail(); ?> + getName()); ?> + getIsAdmin()): ?>
    - +
    diff --git a/src/View/User/profile.phtml b/src/View/User/profile.phtml index a9f92352..b898f75a 100644 --- a/src/View/User/profile.phtml +++ b/src/View/User/profile.phtml @@ -1,4 +1,8 @@ - +

    @@ -8,7 +12,7 @@

    - +
    diff --git a/src/View/WidgetAllProjects/index-projects.phtml b/src/View/WidgetAllProjects/index-projects.phtml index e40264cc..accacb96 100644 --- a/src/View/WidgetAllProjects/index-projects.phtml +++ b/src/View/WidgetAllProjects/index-projects.phtml @@ -102,7 +102,7 @@ foreach($projects as $project):
    - +
    @@ -112,7 +112,7 @@ foreach($projects as $project):
    - (getId()]; ?>) + (getId()]; ?>)
    -

    +

    - +
    diff --git a/src/View/WidgetAllProjects/update.phtml b/src/View/WidgetAllProjects/update.phtml index 096796e8..f5bf9e09 100644 --- a/src/View/WidgetAllProjects/update.phtml +++ b/src/View/WidgetAllProjects/update.phtml @@ -96,12 +96,12 @@ if ($buildCount > 0) {

    - +

    - +
    diff --git a/src/View/WidgetBuildErrors/update.phtml b/src/View/WidgetBuildErrors/update.phtml index 08b4a5eb..79c97b72 100644 --- a/src/View/WidgetBuildErrors/update.phtml +++ b/src/View/WidgetBuildErrors/update.phtml @@ -109,7 +109,7 @@ foreach($builds as $project_id => $project_envs):
    - +
    diff --git a/src/View/WidgetLastBuilds/update.phtml b/src/View/WidgetLastBuilds/update.phtml index 772a2039..bedffa6d 100644 --- a/src/View/WidgetLastBuilds/update.phtml +++ b/src/View/WidgetLastBuilds/update.phtml @@ -58,7 +58,7 @@ use PHPCensor\Model\Build;
  • - +
    getUser(); - <?php print $title; ?><?php print !empty($subtitle) ? ' - ' . $subtitle : ''; ?> + <?= $title; ?><?= (!empty($subtitle) ? ' - ' . $subtitle : ''); ?> - - - - + + + + - - + + - + - - - + + + - - - - + + + + - + - +
    -
  • - getCommitMessage()): ?> - getCommitMessage(); ?>

    + getCommitMessage()); ?> + +

    Branch: getBranch(); ?>
    diff --git a/src/View/Email/long.phtml b/src/View/Email/long.phtml index 33301747..db0c3ce6 100644 --- a/src/View/Email/long.phtml +++ b/src/View/Email/long.phtml @@ -4,7 +4,7 @@ use PHPCensor\Helper\AnsiConverter; ?>

    - getCommitMessage(); ?> + getCommitMessage()); ?>

         getLog()); ?>
    diff --git a/src/View/Email/short.phtml b/src/View/Email/short.phtml
    index 9f6475b9..ec59bd1a 100644
    --- a/src/View/Email/short.phtml
    +++ b/src/View/Email/short.phtml
    @@ -1,3 +1,3 @@
     

    - getCommitMessage(); ?> + getCommitMessage()); ?>

    diff --git a/src/View/WidgetLastBuilds/update.phtml b/src/View/WidgetLastBuilds/update.phtml index bedffa6d..4fabfdf7 100644 --- a/src/View/WidgetLastBuilds/update.phtml +++ b/src/View/WidgetLastBuilds/update.phtml @@ -115,9 +115,10 @@ use PHPCensor\Model\Build; substr($build->getCommitId(), 0, 7), $build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : '' ); - if (!empty($build->getCommitMessage())) { + $buildCommitMessage = htmlspecialchars($build->getCommitMessage()); + if ($buildCommitMessage) { echo '

    '; - print $build->getCommitMessage(); + echo $buildCommitMessage; } } ?> diff --git a/tests/src/Model/BuildTest.php b/tests/src/Model/BuildTest.php index 02ae078f..e34c2c31 100644 --- a/tests/src/Model/BuildTest.php +++ b/tests/src/Model/BuildTest.php @@ -126,32 +126,16 @@ class BuildTest extends \PHPUnit\Framework\TestCase ]; $build = new Build(); - $build->setExtra(json_encode($info)); + $build->setExtra($info); self::assertEquals('Item One', $build->getExtra('item1')); self::assertEquals(2, $build->getExtra('item2')); self::assertNull($build->getExtra('item3')); self::assertEquals($info, $build->getExtra()); - $build->setExtraValue('item3', 'Item Three'); + $build->addExtraValue('item3', 'Item Three'); self::assertEquals('Item One', $build->getExtra('item1')); self::assertEquals('Item Three', $build->getExtra('item3')); - - $build->setExtraValues([ - 'item3' => 'Item Three New', - 'item4' => 4, - ]); - - self::assertEquals('Item One', $build->getExtra('item1')); - self::assertEquals('Item Three New', $build->getExtra('item3')); - self::assertEquals(4, $build->getExtra('item4')); - - self::assertEquals([ - 'item1' => 'Item One', - 'item2' => 2, - 'item3' => 'Item Three New', - 'item4' => 4, - ], $build->getExtra()); } } diff --git a/tests/src/Service/BuildServiceTest.php b/tests/src/Service/BuildServiceTest.php index b3f4d7dc..9726fcdd 100644 --- a/tests/src/Service/BuildServiceTest.php +++ b/tests/src/Service/BuildServiceTest.php @@ -148,7 +148,7 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase $build->setFinishDate(new \DateTime()); $build->setCommitMessage('test'); $build->setCommitterEmail('test@example.com'); - $build->setExtra(json_encode(['item1' => 1001])); + $build->setExtra(['item1' => 1001]); $returnValue = $this->testedService->createDuplicateBuild($build); diff --git a/tests/src/Service/ProjectServiceTest.php b/tests/src/Service/ProjectServiceTest.php index d9cd5862..3e7c7762 100644 --- a/tests/src/Service/ProjectServiceTest.php +++ b/tests/src/Service/ProjectServiceTest.php @@ -48,7 +48,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $options = [ 'ssh_private_key' => 'private', 'ssh_public_key' => 'public', - 'allow_public_status' => 1, + 'allow_public_status' => true, 'build_config' => 'config', 'branch' => 'testbranch', ]; @@ -59,7 +59,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase self::assertEquals('public', $returnValue->getSshPublicKey()); self::assertEquals('config', $returnValue->getBuildConfig()); self::assertEquals('testbranch', $returnValue->getBranch()); - self::assertEquals(1, $returnValue->getAllowPublicStatus()); + self::assertEquals(true, $returnValue->getAllowPublicStatus()); } /** @@ -92,7 +92,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase public function testExecute_EmptyPublicStatus() { $project = new Project(); - $project->setAllowPublicStatus(1); + $project->setAllowPublicStatus(true); $options = [ 'ssh_private_key' => 'private', @@ -102,7 +102,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options); - self::assertEquals(0, $returnValue->getAllowPublicStatus()); + self::assertEquals(false, $returnValue->getAllowPublicStatus()); } public function testExecute_DeleteProject() diff --git a/tests/src/Service/UserServiceTest.php b/tests/src/Service/UserServiceTest.php index cfe9096d..02874586 100644 --- a/tests/src/Service/UserServiceTest.php +++ b/tests/src/Service/UserServiceTest.php @@ -39,14 +39,14 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase 'Test', 'test@example.com', 'internal', - json_encode(['type' => 'internal']), + ['type' => 'internal'], 'testing', false ); self::assertEquals('Test', $user->getName()); self::assertEquals('test@example.com', $user->getEmail()); - self::assertEquals(0, $user->getIsAdmin()); + self::assertEquals(false, $user->getIsAdmin()); self::assertTrue(password_verify('testing', $user->getHash())); } @@ -56,12 +56,12 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase 'Test', 'test@example.com', 'internal', - json_encode(['type' => 'internal']), + ['type' => 'internal'], 'testing', true ); - self::assertEquals(1, $user->getIsAdmin()); + self::assertEquals(true, $user->getIsAdmin()); } public function testExecute_RevokeAdminStatus() @@ -69,10 +69,10 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user = new User(); $user->setEmail('test@example.com'); $user->setName('Test'); - $user->setIsAdmin(1); + $user->setIsAdmin(true); - $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 0); - self::assertEquals(0, $user->getIsAdmin()); + $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', false); + self::assertEquals(false, $user->getIsAdmin()); } public function testExecute_GrantAdminStatus() @@ -80,10 +80,10 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user = new User(); $user->setEmail('test@example.com'); $user->setName('Test'); - $user->setIsAdmin(0); + $user->setIsAdmin(false); - $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 1); - self::assertEquals(1, $user->getIsAdmin()); + $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', true); + self::assertEquals(true, $user->getIsAdmin()); } public function testExecute_ChangesPasswordIfNotEmpty() @@ -91,7 +91,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user = new User(); $user->setHash(password_hash('testing', PASSWORD_DEFAULT)); - $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'newpassword', 0); + $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'newpassword', false); self::assertFalse(password_verify('testing', $user->getHash())); self::assertTrue(password_verify('newpassword', $user->getHash())); } @@ -101,7 +101,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase $user = new User(); $user->setHash(password_hash('testing', PASSWORD_DEFAULT)); - $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', '', 0); + $user = $this->testedService->updateUser($user, 'Test', 'test@example.com', '', false); self::assertTrue(password_verify('testing', $user->getHash())); } } From ad7670e81e4a0b14bde36143711df79772f62725 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 11 Mar 2018 12:13:28 +0700 Subject: [PATCH 23/28] Added unit tests for base models. --- src/Model.php | 4 + src/Model/Base/Build.php | 96 ++++++--- src/Model/Base/BuildError.php | 95 ++++++--- src/Model/Base/BuildMeta.php | 24 ++- src/Model/Base/Environment.php | 24 ++- src/Model/Base/Project.php | 102 +++++---- src/Model/Base/ProjectGroup.php | 24 ++- src/Model/Base/User.php | 64 ++++-- src/Model/BuildError.php | 5 - tests/src/Model/Base/BuildErrorTest.php | 167 +++++++++++++++ tests/src/Model/Base/BuildMetaTest.php | 72 +++++++ tests/src/Model/Base/BuildTest.php | 242 +++++++++++++++++++++ tests/src/Model/Base/EnvironmentTest.php | 72 +++++++ tests/src/Model/Base/ProjectGroupTest.php | 76 +++++++ tests/src/Model/Base/ProjectTest.php | 245 ++++++++++++++++++++++ tests/src/Model/Base/UserTest.php | 152 ++++++++++++++ 16 files changed, 1312 insertions(+), 152 deletions(-) create mode 100644 tests/src/Model/Base/BuildErrorTest.php create mode 100644 tests/src/Model/Base/BuildMetaTest.php create mode 100644 tests/src/Model/Base/BuildTest.php create mode 100644 tests/src/Model/Base/EnvironmentTest.php create mode 100644 tests/src/Model/Base/ProjectGroupTest.php create mode 100644 tests/src/Model/Base/ProjectTest.php create mode 100644 tests/src/Model/Base/UserTest.php diff --git a/src/Model.php b/src/Model.php index df436500..292610eb 100644 --- a/src/Model.php +++ b/src/Model.php @@ -67,10 +67,14 @@ class Model /** * @param string $column + * + * @return boolean */ protected function setModified($column) { $this->modified[$column] = $column; + + return true; } /** diff --git a/src/Model/Base/Build.php b/src/Model/Base/Build.php index dab29ece..c1fc0cab 100644 --- a/src/Model/Base/Build.php +++ b/src/Model/Base/Build.php @@ -50,6 +50,8 @@ class Build extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -57,12 +59,12 @@ class Build extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = (integer)$value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -75,6 +77,8 @@ class Build extends Model /** * @param integer $value + * + * @return boolean */ public function setProjectId($value) { @@ -82,12 +86,12 @@ class Build extends Model $this->validateInt('project_id', $value); if ($this->data['project_id'] === $value) { - return; + return false; } $this->data['project_id'] = $value; - $this->setModified('project_id'); + return $this->setModified('project_id'); } /** @@ -100,6 +104,8 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setCommitId($value) { @@ -107,12 +113,12 @@ class Build extends Model $this->validateString('commit_id', $value); if ($this->data['commit_id'] === $value) { - return; + return false; } $this->data['commit_id'] = $value; - $this->setModified('commit_id'); + return $this->setModified('commit_id'); } /** @@ -125,6 +131,8 @@ class Build extends Model /** * @param integer $value + * + * @return boolean */ public function setStatus($value) { @@ -132,12 +140,12 @@ class Build extends Model $this->validateInt('status', $value); if ($this->data['status'] === $value) { - return; + return false; } $this->data['status'] = $value; - $this->setModified('status'); + return $this->setModified('status'); } /** @@ -150,18 +158,20 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setLog($value) { $this->validateString('log', $value); if ($this->data['log'] === $value) { - return; + return false; } $this->data['log'] = $value; - $this->setModified('log'); + return $this->setModified('log'); } /** @@ -174,6 +184,8 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setBranch($value) { @@ -181,12 +193,12 @@ class Build extends Model $this->validateString('branch', $value); if ($this->data['branch'] === $value) { - return; + return false; } $this->data['branch'] = $value; - $this->setModified('branch'); + return $this->setModified('branch'); } /** @@ -199,18 +211,20 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setTag($value) { $this->validateString('tag', $value); if ($this->data['tag'] === $value) { - return; + return false; } $this->data['tag'] = $value; - $this->setModified('tag'); + return $this->setModified('tag'); } /** @@ -227,18 +241,20 @@ class Build extends Model /** * @param \DateTime $value + * + * @return boolean */ public function setCreateDate(\DateTime $value) { $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { - return; + return false; } $this->data['create_date'] = $stringValue; - $this->setModified('create_date'); + return $this->setModified('create_date'); } /** @@ -255,18 +271,20 @@ class Build extends Model /** * @param \DateTime $value + * + * @return boolean */ public function setStartDate(\DateTime $value) { $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['start_date'] === $stringValue) { - return; + return false; } $this->data['start_date'] = $stringValue; - $this->setModified('start_date'); + return $this->setModified('start_date'); } /** @@ -283,18 +301,20 @@ class Build extends Model /** * @param \DateTime $value + * + * @return boolean */ public function setFinishDate(\DateTime $value) { $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['finish_date'] === $stringValue) { - return; + return false; } $this->data['finish_date'] = $stringValue; - $this->setModified('finish_date'); + return $this->setModified('finish_date'); } /** @@ -307,18 +327,20 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setCommitterEmail($value) { $this->validateString('committer_email', $value); if ($this->data['committer_email'] === $value) { - return; + return false; } $this->data['committer_email'] = $value; - $this->setModified('committer_email'); + return $this->setModified('committer_email'); } /** @@ -331,18 +353,20 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setCommitMessage($value) { $this->validateString('commit_message', $value); if ($this->data['commit_message'] === $value) { - return; + return false; } $this->data['commit_message'] = $value; - $this->setModified('commit_message'); + return $this->setModified('commit_message'); } /** @@ -365,6 +389,8 @@ class Build extends Model /** * @param array $value + * + * @return boolean */ public function setExtra(array $value) { @@ -372,12 +398,12 @@ class Build extends Model $extra = json_encode($value); if ($this->data['extra'] === $extra) { - return; + return false; } $this->data['extra'] = $extra; - $this->setModified('extra'); + return $this->setModified('extra'); } /** @@ -390,18 +416,20 @@ class Build extends Model /** * @param string $value + * + * @return boolean */ public function setEnvironment($value) { $this->validateString('environment', $value); if ($this->data['environment'] === $value) { - return; + return false; } $this->data['environment'] = $value; - $this->setModified('environment'); + return $this->setModified('environment'); } /** @@ -414,18 +442,20 @@ class Build extends Model /** * @param integer $value + * + * @return boolean */ public function setSource($value) { $this->validateInt('source', $value); if ($this->data['source'] === $value) { - return; + return false; } $this->data['source'] = $value; - $this->setModified('source'); + return $this->setModified('source'); } /** @@ -438,6 +468,8 @@ class Build extends Model /** * @param integer $value + * + * @return boolean */ public function setUserId($value) { @@ -445,11 +477,11 @@ class Build extends Model $this->validateInt('user_id', $value); if ($this->data['user_id'] === $value) { - return; + return false; } $this->data['user_id'] = $value; - $this->setModified('user_id'); + return $this->setModified('user_id'); } } diff --git a/src/Model/Base/BuildError.php b/src/Model/Base/BuildError.php index 45ffb108..a760e777 100644 --- a/src/Model/Base/BuildError.php +++ b/src/Model/Base/BuildError.php @@ -6,6 +6,11 @@ use PHPCensor\Model; class BuildError extends Model { + const SEVERITY_CRITICAL = 0; + const SEVERITY_HIGH = 1; + const SEVERITY_NORMAL = 2; + const SEVERITY_LOW = 3; + /** * @var string */ @@ -15,17 +20,17 @@ class BuildError extends Model * @var array */ protected $data = [ - 'id' => null, - 'build_id' => null, - 'plugin' => null, - 'file' => null, - 'line_start' => null, - 'line_end' => null, - 'severity' => null, - 'message' => null, - 'create_date' => null, - 'hash' => null, - 'is_new' => null, + 'id' => null, + 'build_id' => null, + 'plugin' => null, + 'file' => null, + 'line_start' => null, + 'line_end' => null, + 'severity' => null, + 'message' => null, + 'create_date' => null, + 'hash' => null, + 'is_new' => null, ]; /** @@ -38,6 +43,8 @@ class BuildError extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -45,12 +52,12 @@ class BuildError extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = $value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -63,6 +70,8 @@ class BuildError extends Model /** * @param integer $value + * + * @return boolean */ public function setBuildId($value) { @@ -70,12 +79,12 @@ class BuildError extends Model $this->validateInt('build_id', $value); if ($this->data['build_id'] === $value) { - return; + return false; } $this->data['build_id'] = $value; - $this->setModified('build_id'); + return $this->setModified('build_id'); } /** @@ -88,6 +97,8 @@ class BuildError extends Model /** * @param string $value + * + * @return boolean */ public function setPlugin($value) { @@ -95,12 +106,12 @@ class BuildError extends Model $this->validateString('plugin', $value); if ($this->data['plugin'] === $value) { - return; + return false; } $this->data['plugin'] = $value; - $this->setModified('plugin'); + return $this->setModified('plugin'); } /** @@ -113,18 +124,20 @@ class BuildError extends Model /** * @param string $value + * + * @return boolean */ public function setFile($value) { $this->validateString('file', $value); if ($this->data['file'] === $value) { - return; + return false; } $this->data['file'] = $value; - $this->setModified('file'); + return $this->setModified('file'); } /** @@ -137,18 +150,20 @@ class BuildError extends Model /** * @param integer $value + * + * @return boolean */ public function setLineStart($value) { $this->validateInt('line_start', $value); if ($this->data['line_start'] === $value) { - return; + return false; } $this->data['line_start'] = $value; - $this->setModified('line_start'); + return $this->setModified('line_start'); } /** @@ -161,18 +176,20 @@ class BuildError extends Model /** * @param integer $value + * + * @return boolean */ public function setLineEnd($value) { $this->validateInt('line_end', $value); if ($this->data['line_end'] === $value) { - return; + return false; } $this->data['line_end'] = $value; - $this->setModified('line_end'); + return $this->setModified('line_end'); } /** @@ -185,6 +202,8 @@ class BuildError extends Model /** * @param integer $value + * + * @return boolean */ public function setSeverity($value) { @@ -192,12 +211,12 @@ class BuildError extends Model $this->validateInt('severity', $value); if ($this->data['severity'] === $value) { - return; + return false; } $this->data['severity'] = $value; - $this->setModified('severity'); + return $this->setModified('severity'); } /** @@ -210,6 +229,8 @@ class BuildError extends Model /** * @param string $value + * + * @return boolean */ public function setMessage($value) { @@ -217,12 +238,12 @@ class BuildError extends Model $this->validateString('message', $value); if ($this->data['message'] === $value) { - return; + return false; } $this->data['message'] = $value; - $this->setModified('message'); + return $this->setModified('message'); } /** @@ -239,6 +260,8 @@ class BuildError extends Model /** * @param \DateTime $value + * + * @return boolean */ public function setCreateDate(\DateTime $value) { @@ -247,12 +270,12 @@ class BuildError extends Model $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { - return; + return false; } $this->data['create_date'] = $stringValue; - $this->setModified('create_date'); + return $this->setModified('create_date'); } /** @@ -265,6 +288,8 @@ class BuildError extends Model /** * @param string $value + * + * @return boolean */ public function setHash($value) { @@ -272,12 +297,12 @@ class BuildError extends Model $this->validateString('hash', $value); if ($this->data['hash'] === $value) { - return; + return false; } $this->data['hash'] = $value; - $this->setModified('hash'); + return $this->setModified('hash'); } /** @@ -290,18 +315,20 @@ class BuildError extends Model /** * @param boolean $value + * + * @return boolean */ public function setIsNew($value) { $this->validateNotNull('is_new', $value); $this->validateBoolean('is_new', $value); - if ($this->data['is_new'] === $value) { - return; + if ($this->data['is_new'] === (integer)$value) { + return false; } $this->data['is_new'] = (integer)$value; - $this->setModified('is_new'); + return $this->setModified('is_new'); } } diff --git a/src/Model/Base/BuildMeta.php b/src/Model/Base/BuildMeta.php index a98a960f..338c2a50 100644 --- a/src/Model/Base/BuildMeta.php +++ b/src/Model/Base/BuildMeta.php @@ -31,6 +31,8 @@ class BuildMeta extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -38,12 +40,12 @@ class BuildMeta extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = $value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -56,6 +58,8 @@ class BuildMeta extends Model /** * @param integer $value + * + * @return boolean */ public function setBuildId($value) { @@ -63,12 +67,12 @@ class BuildMeta extends Model $this->validateInt('build_id', $value); if ($this->data['build_id'] === $value) { - return; + return false ; } $this->data['build_id'] = $value; - $this->setModified('build_id'); + return $this->setModified('build_id'); } /** @@ -81,6 +85,8 @@ class BuildMeta extends Model /** * @param string $value + * + * @return boolean */ public function setMetaKey($value) { @@ -88,12 +94,12 @@ class BuildMeta extends Model $this->validateString('meta_key', $value); if ($this->data['meta_key'] === $value) { - return; + return false; } $this->data['meta_key'] = $value; - $this->setModified('meta_key'); + return $this->setModified('meta_key'); } /** @@ -106,6 +112,8 @@ class BuildMeta extends Model /** * @param string $value + * + * @return boolean */ public function setMetaValue($value) { @@ -113,11 +121,11 @@ class BuildMeta extends Model $this->validateString('meta_value', $value); if ($this->data['meta_value'] === $value) { - return; + return false; } $this->data['meta_value'] = $value; - $this->setModified('meta_value'); + return $this->setModified('meta_value'); } } diff --git a/src/Model/Base/Environment.php b/src/Model/Base/Environment.php index 10d17a09..d160cb57 100644 --- a/src/Model/Base/Environment.php +++ b/src/Model/Base/Environment.php @@ -31,6 +31,8 @@ class Environment extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -38,12 +40,12 @@ class Environment extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = $value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -56,6 +58,8 @@ class Environment extends Model /** * @param integer $value + * + * @return boolean */ public function setProjectId($value) { @@ -63,12 +67,12 @@ class Environment extends Model $this->validateInt('project_id', $value); if ($this->data['project_id'] === $value) { - return; + return false; } $this->data['project_id'] = $value; - $this->setModified('project_id'); + return $this->setModified('project_id'); } /** @@ -81,6 +85,8 @@ class Environment extends Model /** * @param string $value + * + * @return boolean */ public function setName($value) { @@ -88,12 +94,12 @@ class Environment extends Model $this->validateString('name', $value); if ($this->data['name'] === $value) { - return; + return false; } $this->data['name'] = $value; - $this->setModified('name'); + return $this->setModified('name'); } /** @@ -111,6 +117,8 @@ class Environment extends Model /** * @param array $value + * + * @return boolean */ public function setBranches(array $value) { @@ -118,11 +126,11 @@ class Environment extends Model $branches = implode("\n", $value); if ($this->data['branches'] === $branches) { - return; + return false; } $this->data['branches'] = $branches; - $this->setModified('branches'); + return $this->setModified('branches'); } } diff --git a/src/Model/Base/Project.php b/src/Model/Base/Project.php index f47cbb22..25f94154 100644 --- a/src/Model/Base/Project.php +++ b/src/Model/Base/Project.php @@ -43,6 +43,8 @@ class Project extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -50,12 +52,12 @@ class Project extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = $value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -68,6 +70,8 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setTitle($value) { @@ -75,12 +79,12 @@ class Project extends Model $this->validateString('title', $value); if ($this->data['title'] === $value) { - return; + return false; } $this->data['title'] = $value; - $this->setModified('title'); + return $this->setModified('title'); } /** @@ -93,6 +97,8 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setReference($value) { @@ -100,12 +106,12 @@ class Project extends Model $this->validateString('reference', $value); if ($this->data['reference'] === $value) { - return; + return false; } $this->data['reference'] = $value; - $this->setModified('reference'); + return $this->setModified('reference'); } /** @@ -134,6 +140,8 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setBranch($value) { @@ -141,12 +149,12 @@ class Project extends Model $this->validateString('branch', $value); if ($this->data['branch'] === $value) { - return; + return false; } $this->data['branch'] = $value; - $this->setModified('branch'); + return $this->setModified('branch'); } /** @@ -159,19 +167,21 @@ class Project extends Model /** * @param boolean $value + * + * @return boolean */ public function setDefaultBranchOnly($value) { $this->validateNotNull('default_branch_only', $value); $this->validateBoolean('default_branch_only', $value); - if ($this->data['default_branch_only'] === $value) { - return; + if ($this->data['default_branch_only'] === (integer)$value) { + return false; } $this->data['default_branch_only'] = (integer)$value; - $this->setModified('default_branch_only'); + return $this->setModified('default_branch_only'); } /** @@ -184,18 +194,20 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setSshPrivateKey($value) { $this->validateString('ssh_private_key', $value); if ($this->data['ssh_private_key'] === $value) { - return; + return false; } $this->data['ssh_private_key'] = $value; - $this->setModified('ssh_private_key'); + return $this->setModified('ssh_private_key'); } /** @@ -208,18 +220,20 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setSshPublicKey($value) { $this->validateString('ssh_public_key', $value); if ($this->data['ssh_public_key'] === $value) { - return; + return false; } $this->data['ssh_public_key'] = $value; - $this->setModified('ssh_public_key'); + return $this->setModified('ssh_public_key'); } /** @@ -232,6 +246,8 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setType($value) { @@ -239,12 +255,12 @@ class Project extends Model $this->validateString('type', $value); if ($this->data['type'] === $value) { - return; + return false; } $this->data['type'] = $value; - $this->setModified('type'); + return $this->setModified('type'); } /** @@ -267,6 +283,8 @@ class Project extends Model /** * @param array $value + * + * @return boolean */ public function setAccessInformation(array $value) { @@ -274,12 +292,12 @@ class Project extends Model $accessInformation = json_encode($value); if ($this->data['access_information'] === $accessInformation) { - return; + return false; } $this->data['access_information'] = $accessInformation; - $this->setModified('access_information'); + return $this->setModified('access_information'); } @@ -293,18 +311,20 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setLastCommit($value) { $this->validateString('last_commit', $value); if ($this->data['last_commit'] === $value) { - return; + return false; } $this->data['last_commit'] = $value; - $this->setModified('last_commit'); + return $this->setModified('last_commit'); } /** @@ -317,18 +337,20 @@ class Project extends Model /** * @param string $value + * + * @return boolean */ public function setBuildConfig($value) { $this->validateString('build_config', $value); if ($this->data['build_config'] === $value) { - return; + return false; } $this->data['build_config'] = $value; - $this->setModified('build_config'); + return $this->setModified('build_config'); } /** @@ -341,19 +363,21 @@ class Project extends Model /** * @param boolean $value + * + * @return boolean */ public function setAllowPublicStatus($value) { $this->validateNotNull('allow_public_status', $value); $this->validateBoolean('allow_public_status', $value); - if ($this->data['allow_public_status'] === $value) { - return; + if ($this->data['allow_public_status'] === (integer)$value) { + return false; } $this->data['allow_public_status'] = (integer)$value; - $this->setModified('allow_public_status'); + return $this->setModified('allow_public_status'); } /** @@ -366,19 +390,21 @@ class Project extends Model /** * @param boolean $value + * + * @return boolean */ public function setArchived($value) { $this->validateNotNull('archived', $value); $this->validateBoolean('archived', $value); - if ($this->data['archived'] === $value) { - return; + if ($this->data['archived'] === (integer)$value) { + return false; } $this->data['archived'] = (integer)$value; - $this->setModified('archived'); + return $this->setModified('archived'); } /** @@ -391,6 +417,8 @@ class Project extends Model /** * @param integer $value + * + * @return boolean */ public function setGroupId($value) { @@ -398,12 +426,12 @@ class Project extends Model $this->validateInt('group_id', $value); if ($this->data['group_id'] === $value) { - return; + return false; } $this->data['group_id'] = $value; - $this->setModified('group_id'); + return $this->setModified('group_id'); } /** @@ -420,18 +448,20 @@ class Project extends Model /** * @param \DateTime $value + * + * @return boolean */ public function setCreateDate(\DateTime $value) { $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { - return; + return false; } $this->data['create_date'] = $stringValue; - $this->setModified('create_date'); + return $this->setModified('create_date'); } /** @@ -444,6 +474,8 @@ class Project extends Model /** * @param integer $value + * + * @return boolean */ public function setUserId($value) { @@ -451,11 +483,11 @@ class Project extends Model $this->validateInt('user_id', $value); if ($this->data['user_id'] === $value) { - return; + return false; } $this->data['user_id'] = $value; - $this->setModified('user_id'); + return $this->setModified('user_id'); } } diff --git a/src/Model/Base/ProjectGroup.php b/src/Model/Base/ProjectGroup.php index 0d61884f..c78c45a1 100644 --- a/src/Model/Base/ProjectGroup.php +++ b/src/Model/Base/ProjectGroup.php @@ -31,6 +31,8 @@ class ProjectGroup extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -38,12 +40,12 @@ class ProjectGroup extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = $value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -56,6 +58,8 @@ class ProjectGroup extends Model /** * @param string $value + * + * @return boolean */ public function setTitle($value) { @@ -63,12 +67,12 @@ class ProjectGroup extends Model $this->validateString('title', $value); if ($this->data['title'] === $value) { - return; + return false; } $this->data['title'] = $value; - $this->setModified('title'); + return $this->setModified('title'); } /** @@ -85,18 +89,20 @@ class ProjectGroup extends Model /** * @param \DateTime $value + * + * @return boolean */ public function setCreateDate(\DateTime $value) { $stringValue = $value->format('Y-m-d H:i:s'); if ($this->data['create_date'] === $stringValue) { - return; + return false; } $this->data['create_date'] = $stringValue; - $this->setModified('create_date'); + return $this->setModified('create_date'); } /** @@ -109,6 +115,8 @@ class ProjectGroup extends Model /** * @param integer $value + * + * @return boolean */ public function setUserId($value) { @@ -116,11 +124,11 @@ class ProjectGroup extends Model $this->validateInt('user_id', $value); if ($this->data['user_id'] === $value) { - return; + return false; } $this->data['user_id'] = $value; - $this->setModified('user_id'); + return $this->setModified('user_id'); } } diff --git a/src/Model/Base/User.php b/src/Model/Base/User.php index 01c82c1e..cd49424b 100644 --- a/src/Model/Base/User.php +++ b/src/Model/Base/User.php @@ -37,6 +37,8 @@ class User extends Model /** * @param integer $value + * + * @return boolean */ public function setId($value) { @@ -44,12 +46,12 @@ class User extends Model $this->validateInt('id', $value); if ($this->data['id'] === $value) { - return; + return false; } $this->data['id'] = $value; - $this->setModified('id'); + return $this->setModified('id'); } /** @@ -62,6 +64,8 @@ class User extends Model /** * @param string $value + * + * @return boolean */ public function setEmail($value) { @@ -69,12 +73,12 @@ class User extends Model $this->validateString('email', $value); if ($this->data['email'] === $value) { - return; + return false; } $this->data['email'] = $value; - $this->setModified('email'); + return $this->setModified('email'); } /** @@ -87,6 +91,8 @@ class User extends Model /** * @param string $value + * + * @return boolean */ public function setHash($value) { @@ -94,12 +100,12 @@ class User extends Model $this->validateString('hash', $value); if ($this->data['hash'] === $value) { - return; + return false; } $this->data['hash'] = $value; - $this->setModified('hash'); + return $this->setModified('hash'); } /** @@ -112,19 +118,21 @@ class User extends Model /** * @param boolean $value + * + * @return boolean */ public function setIsAdmin($value) { $this->validateNotNull('is_admin', $value); $this->validateBoolean('is_admin', $value); - if ($this->data['is_admin'] === $value) { - return; + if ($this->data['is_admin'] === (integer)$value) { + return false; } $this->data['is_admin'] = (integer)$value; - $this->setModified('is_admin'); + return $this->setModified('is_admin'); } /** @@ -137,6 +145,8 @@ class User extends Model /** * @param string $value + * + * @return boolean */ public function setName($value) { @@ -144,12 +154,12 @@ class User extends Model $this->validateString('name', $value); if ($this->data['name'] === $value) { - return; + return false; } $this->data['name'] = $value; - $this->setModified('name'); + return $this->setModified('name'); } /** @@ -162,16 +172,18 @@ class User extends Model /** * @param string $value + * + * @return boolean */ public function setLanguage($value) { if ($this->data['language'] === $value) { - return; + return false; } $this->data['language'] = $value; - $this->setModified('language'); + return $this->setModified('language'); } /** @@ -184,18 +196,20 @@ class User extends Model /** * @param integer $value + * + * @return boolean */ public function setPerPage($value) { $this->validateInt('per_page', $value); if ($this->data['per_page'] === $value) { - return; + return false; } $this->data['per_page'] = $value; - $this->setModified('per_page'); + return $this->setModified('per_page'); } /** @@ -208,6 +222,8 @@ class User extends Model /** * @param string $value + * + * @return boolean */ public function setProviderKey($value) { @@ -215,12 +231,12 @@ class User extends Model $this->validateString('provider_key', $value); if ($this->data['provider_key'] === $value) { - return; + return false; } $this->data['provider_key'] = $value; - $this->setModified('provider_key'); + return $this->setModified('provider_key'); } /** @@ -230,7 +246,7 @@ class User extends Model */ public function getProviderData($key = null) { - $data = json_decode($this->data['provider_data'], true); + $data = json_decode($this->data['provider_data'], true); $providerData = null; if (is_null($key)) { $providerData = $data; @@ -243,6 +259,8 @@ class User extends Model /** * @param array $value + * + * @return boolean */ public function setProviderData(array $value) { @@ -250,12 +268,12 @@ class User extends Model $providerData = json_encode($value); if ($this->data['provider_data'] === $providerData) { - return; + return false; } $this->data['provider_data'] = $providerData; - $this->setModified('provider_data'); + return $this->setModified('provider_data'); } /** @@ -268,17 +286,19 @@ class User extends Model /** * @param string $value + * + * @return boolean */ public function setRememberKey($value) { $this->validateString('remember_key', $value); if ($this->data['remember_key'] === $value) { - return; + return false; } $this->data['remember_key'] = $value; - $this->setModified('remember_key'); + return $this->setModified('remember_key'); } } diff --git a/src/Model/BuildError.php b/src/Model/BuildError.php index f7a6f29f..9c995dc4 100644 --- a/src/Model/BuildError.php +++ b/src/Model/BuildError.php @@ -8,11 +8,6 @@ use PHPCensor\Store\Factory; class BuildError extends BaseBuildError { - const SEVERITY_CRITICAL = 0; - const SEVERITY_HIGH = 1; - const SEVERITY_NORMAL = 2; - const SEVERITY_LOW = 3; - /** * @return Build|null */ diff --git a/tests/src/Model/Base/BuildErrorTest.php b/tests/src/Model/Base/BuildErrorTest.php new file mode 100644 index 00000000..48f8c442 --- /dev/null +++ b/tests/src/Model/Base/BuildErrorTest.php @@ -0,0 +1,167 @@ + null, + 'build_id' => null, + 'plugin' => null, + 'file' => null, + 'line_start' => null, + 'line_end' => null, + 'severity' => null, + 'message' => null, + 'create_date' => null, + 'hash' => null, + 'is_new' => null, + ], $buildError->getDataArray()); + } + + public function testId() + { + $buildError = new BuildError(); + + $result = $buildError->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $buildError->getId()); + + $result = $buildError->setId(100); + self::assertEquals(false, $result); + } + + public function testBuildId() + { + $buildError = new BuildError(); + + $result = $buildError->setBuildId(200); + self::assertEquals(true, $result); + self::assertEquals(200, $buildError->getBuildId()); + + $result = $buildError->setBuildId(200); + self::assertEquals(false, $result); + } + + public function testPlugin() + { + $buildError = new BuildError(); + + $result = $buildError->setPlugin('plugin'); + self::assertEquals(true, $result); + self::assertEquals('plugin', $buildError->getPlugin()); + + $result = $buildError->setPlugin('plugin'); + self::assertEquals(false, $result); + } + + public function testFile() + { + $buildError = new BuildError(); + + $result = $buildError->setFile('file.php'); + self::assertEquals(true, $result); + self::assertEquals('file.php', $buildError->getFile()); + + $result = $buildError->setFile('file.php'); + self::assertEquals(false, $result); + } + + public function testLineStart() + { + $buildError = new BuildError(); + + $result = $buildError->setLineStart(5); + self::assertEquals(true, $result); + self::assertEquals(5, $buildError->getLineStart()); + + $result = $buildError->setLineStart(5); + self::assertEquals(false, $result); + } + + public function testLineEnd() + { + $buildError = new BuildError(); + + $result = $buildError->setLineEnd(10); + self::assertEquals(true, $result); + self::assertEquals(10, $buildError->getLineEnd()); + + $result = $buildError->setLineEnd(10); + self::assertEquals(false, $result); + } + + public function testSeverity() + { + $buildError = new BuildError(); + + $result = $buildError->setSeverity(BuildError::SEVERITY_CRITICAL); + self::assertEquals(true, $result); + self::assertEquals(BuildError::SEVERITY_CRITICAL, $buildError->getSeverity()); + + $result = $buildError->setSeverity(BuildError::SEVERITY_CRITICAL); + self::assertEquals(false, $result); + } + + public function testMessage() + { + $buildError = new BuildError(); + + $result = $buildError->setMessage('message'); + self::assertEquals(true, $result); + self::assertEquals('message', $buildError->getMessage()); + + $result = $buildError->setMessage('message'); + self::assertEquals(false, $result); + } + + public function testCreateDate() + { + $buildError = new BuildError(); + self::assertEquals(null, $buildError->getCreateDate()); + + $buildError = new BuildError(); + $createDate = new \DateTime(); + + $result = $buildError->setCreateDate($createDate); + self::assertEquals(true, $result); + self::assertEquals($createDate->getTimestamp(), $buildError->getCreateDate()->getTimestamp()); + + $result = $buildError->setCreateDate($createDate); + self::assertEquals(false, $result); + } + + public function testHash() + { + $buildError = new BuildError(); + + $result = $buildError->setHash('hash'); + self::assertEquals(true, $result); + self::assertEquals('hash', $buildError->getHash()); + + $result = $buildError->setHash('hash'); + self::assertEquals(false, $result); + } + + public function testIsNew() + { + $buildError = new BuildError(); + + $result = $buildError->setIsNew(true); + self::assertEquals(true, $result); + self::assertEquals(true, $buildError->getIsNew()); + + $result = $buildError->setIsNew(true); + self::assertEquals(false, $result); + } +} diff --git a/tests/src/Model/Base/BuildMetaTest.php b/tests/src/Model/Base/BuildMetaTest.php new file mode 100644 index 00000000..5ae55f85 --- /dev/null +++ b/tests/src/Model/Base/BuildMetaTest.php @@ -0,0 +1,72 @@ + null, + 'build_id' => null, + 'meta_key' => null, + 'meta_value' => null, + ], $buildMeta->getDataArray()); + } + + public function testId() + { + $buildMeta = new BuildMeta(); + + $result = $buildMeta->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $buildMeta->getId()); + + $result = $buildMeta->setId(100); + self::assertEquals(false, $result); + } + + public function testBuildId() + { + $buildMeta = new BuildMeta(); + + $result = $buildMeta->setBuildId(200); + self::assertEquals(true, $result); + self::assertEquals(200, $buildMeta->getBuildId()); + + $result = $buildMeta->setBuildId(200); + self::assertEquals(false, $result); + } + + public function testMetaKey() + { + $buildMeta = new BuildMeta(); + + $result = $buildMeta->setMetaKey('key'); + self::assertEquals(true, $result); + self::assertEquals('key', $buildMeta->getMetaKey()); + + $result = $buildMeta->setMetaKey('key'); + self::assertEquals(false, $result); + } + + public function testMetaValue() + { + $buildMeta = new BuildMeta(); + + $result = $buildMeta->setMetaValue('value'); + self::assertEquals(true, $result); + self::assertEquals('value', $buildMeta->getMetaValue()); + + $result = $buildMeta->setMetaValue('value'); + self::assertEquals(false, $result); + } +} diff --git a/tests/src/Model/Base/BuildTest.php b/tests/src/Model/Base/BuildTest.php new file mode 100644 index 00000000..41785c88 --- /dev/null +++ b/tests/src/Model/Base/BuildTest.php @@ -0,0 +1,242 @@ + null, + 'project_id' => null, + 'commit_id' => null, + 'status' => null, + 'log' => null, + 'branch' => null, + 'tag' => null, + 'create_date' => null, + 'start_date' => null, + 'finish_date' => null, + 'committer_email' => null, + 'commit_message' => null, + 'extra' => null, + 'environment' => null, + 'source' => Build::SOURCE_UNKNOWN, + 'user_id' => 0, + ], $build->getDataArray()); + } + + public function testId() + { + $build = new Build(); + + $result = $build->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $build->getId()); + + $result = $build->setId(100); + self::assertEquals(false, $result); + } + + public function testProjectId() + { + $build = new Build(); + + $result = $build->setProjectId(200); + self::assertEquals(true, $result); + self::assertEquals(200, $build->getProjectId()); + + $result = $build->setProjectId(200); + self::assertEquals(false, $result); + } + + public function testCommitId() + { + $build = new Build(); + + $result = $build->setCommitId('commit'); + self::assertEquals(true, $result); + self::assertEquals('commit', $build->getCommitId()); + + $result = $build->setCommitId('commit'); + self::assertEquals(false, $result); + } + + public function testStatus() + { + $build = new Build(); + + $result = $build->setStatus(Build::STATUS_FAILED); + self::assertEquals(true, $result); + self::assertEquals(Build::STATUS_FAILED, $build->getStatus()); + + $result = $build->setStatus(Build::STATUS_FAILED); + self::assertEquals(false, $result); + } + + public function testLog() + { + $build = new Build(); + + $result = $build->setLog('log'); + self::assertEquals(true, $result); + self::assertEquals('log', $build->getLog()); + + $result = $build->setLog('log'); + self::assertEquals(false, $result); + } + + public function testBranch() + { + $build = new Build(); + + $result = $build->setBranch('branch'); + self::assertEquals(true, $result); + self::assertEquals('branch', $build->getBranch()); + + $result = $build->setBranch('branch'); + self::assertEquals(false, $result); + } + + public function testTag() + { + $build = new Build(); + + $result = $build->setTag('tag'); + self::assertEquals(true, $result); + self::assertEquals('tag', $build->getTag()); + + $result = $build->setTag('tag'); + self::assertEquals(false, $result); + } + + public function testCreateDate() + { + $build = new Build(); + self::assertEquals(null, $build->getCreateDate()); + + $build = new Build(); + $createDate = new \DateTime(); + + $result = $build->setCreateDate($createDate); + self::assertEquals(true, $result); + self::assertEquals($createDate->getTimestamp(), $build->getCreateDate()->getTimestamp()); + + $result = $build->setCreateDate($createDate); + self::assertEquals(false, $result); + } + + public function testStartDate() + { + $build = new Build(); + self::assertEquals(null, $build->getStartDate()); + + $build = new Build(); + $createDate = new \DateTime(); + + $result = $build->setStartDate($createDate); + self::assertEquals(true, $result); + self::assertEquals($createDate->getTimestamp(), $build->getStartDate()->getTimestamp()); + + $result = $build->setStartDate($createDate); + self::assertEquals(false, $result); + } + + public function testFinishDate() + { + $build = new Build(); + self::assertEquals(null, $build->getFinishDate()); + + $build = new Build(); + $createDate = new \DateTime(); + + $result = $build->setFinishDate($createDate); + self::assertEquals(true, $result); + self::assertEquals($createDate->getTimestamp(), $build->getFinishDate()->getTimestamp()); + + $result = $build->setFinishDate($createDate); + self::assertEquals(false, $result); + } + + public function testCommitterEmail() + { + $build = new Build(); + + $result = $build->setCommitterEmail('email@email.com'); + self::assertEquals(true, $result); + self::assertEquals('email@email.com', $build->getCommitterEmail()); + + $result = $build->setCommitterEmail('email@email.com'); + self::assertEquals(false, $result); + } + + public function testCommitMessage() + { + $build = new Build(); + + $result = $build->setCommitMessage('message'); + self::assertEquals(true, $result); + self::assertEquals('message', $build->getCommitMessage()); + + $result = $build->setCommitMessage('message'); + self::assertEquals(false, $result); + } + + public function testExtra() + { + $build = new Build(); + + $result = $build->setExtra(['key-1' => 'value-1', 'key-2' => 'value-2']); + self::assertEquals(true, $result); + self::assertEquals(['key-1' => 'value-1', 'key-2' => 'value-2'], $build->getExtra()); + self::assertEquals('value-1', $build->getExtra('key-1')); + self::assertEquals(null, $build->getExtra('key-3')); + + $result = $build->setExtra(['key-1' => 'value-1', 'key-2' => 'value-2']); + self::assertEquals(false, $result); + } + + public function testEnvironment() + { + $build = new Build(); + + $result = $build->setEnvironment('environment'); + self::assertEquals(true, $result); + self::assertEquals('environment', $build->getEnvironment()); + + $result = $build->setEnvironment('environment'); + self::assertEquals(false, $result); + } + + public function testSource() + { + $build = new Build(); + + $result = $build->setSource(Build::SOURCE_WEBHOOK_PULL_REQUEST); + self::assertEquals(true, $result); + self::assertEquals(Build::SOURCE_WEBHOOK_PULL_REQUEST, $build->getSource()); + + $result = $build->setSource(Build::SOURCE_WEBHOOK_PULL_REQUEST); + self::assertEquals(false, $result); + } + + public function testUserId() + { + $build = new Build(); + + $result = $build->setUserId(300); + self::assertEquals(true, $result); + self::assertEquals(300, $build->getUserId()); + + $result = $build->setUserId(300); + self::assertEquals(false, $result); + } +} diff --git a/tests/src/Model/Base/EnvironmentTest.php b/tests/src/Model/Base/EnvironmentTest.php new file mode 100644 index 00000000..f29d9458 --- /dev/null +++ b/tests/src/Model/Base/EnvironmentTest.php @@ -0,0 +1,72 @@ + null, + 'project_id' => null, + 'name' => null, + 'branches' => null, + ], $environment->getDataArray()); + } + + public function testId() + { + $environment = new Environment(); + + $result = $environment->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $environment->getId()); + + $result = $environment->setId(100); + self::assertEquals(false, $result); + } + + public function testProjectId() + { + $environment = new Environment(); + + $result = $environment->setProjectId(200); + self::assertEquals(true, $result); + self::assertEquals(200, $environment->getProjectId()); + + $result = $environment->setProjectId(200); + self::assertEquals(false, $result); + } + + public function testName() + { + $environment = new Environment(); + + $result = $environment->setName('name'); + self::assertEquals(true, $result); + self::assertEquals('name', $environment->getName()); + + $result = $environment->setName('name'); + self::assertEquals(false, $result); + } + + public function testBranches() + { + $environment = new Environment(); + + $result = $environment->setBranches(['branch-1', 'branch-2']); + self::assertEquals(true, $result); + self::assertEquals(['branch-1', 'branch-2'], $environment->getBranches()); + + $result = $environment->setBranches(['branch-1', 'branch-2']); + self::assertEquals(false, $result); + } +} diff --git a/tests/src/Model/Base/ProjectGroupTest.php b/tests/src/Model/Base/ProjectGroupTest.php new file mode 100644 index 00000000..34434dba --- /dev/null +++ b/tests/src/Model/Base/ProjectGroupTest.php @@ -0,0 +1,76 @@ + null, + 'title' => null, + 'create_date' => null, + 'user_id' => 0, + ], $projectGroup->getDataArray()); + } + + public function testId() + { + $projectGroup = new ProjectGroup(); + + $result = $projectGroup->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $projectGroup->getId()); + + $result = $projectGroup->setId(100); + self::assertEquals(false, $result); + } + + public function testTitle() + { + $projectGroup = new ProjectGroup(); + + $result = $projectGroup->setTitle('title'); + self::assertEquals(true, $result); + self::assertEquals('title', $projectGroup->getTitle()); + + $result = $projectGroup->setTitle('title'); + self::assertEquals(false, $result); + } + + public function testCreateDate() + { + $projectGroup = new ProjectGroup(); + self::assertEquals(null, $projectGroup->getCreateDate()); + + $projectGroup = new ProjectGroup(); + $createDate = new \DateTime(); + + $result = $projectGroup->setCreateDate($createDate); + self::assertEquals(true, $result); + self::assertEquals($createDate->getTimestamp(), $projectGroup->getCreateDate()->getTimestamp()); + + $result = $projectGroup->setCreateDate($createDate); + self::assertEquals(false, $result); + } + + public function testUserId() + { + $projectGroup = new ProjectGroup(); + + $result = $projectGroup->setUserId(200); + self::assertEquals(true, $result); + self::assertEquals(200, $projectGroup->getUserId()); + + $result = $projectGroup->setUserId(200); + self::assertEquals(false, $result); + } +} diff --git a/tests/src/Model/Base/ProjectTest.php b/tests/src/Model/Base/ProjectTest.php new file mode 100644 index 00000000..6f8e2daa --- /dev/null +++ b/tests/src/Model/Base/ProjectTest.php @@ -0,0 +1,245 @@ + null, + 'title' => null, + 'reference' => null, + 'branch' => null, + 'default_branch_only' => null, + 'ssh_private_key' => null, + 'ssh_public_key' => null, + 'type' => null, + 'access_information' => null, + 'last_commit' => null, + 'build_config' => null, + 'allow_public_status' => null, + 'archived' => null, + 'group_id' => null, + 'create_date' => null, + 'user_id' => 0, + ], $project->getDataArray()); + } + + public function testId() + { + $project = new Project(); + + $result = $project->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $project->getId()); + + $result = $project->setId(100); + self::assertEquals(false, $result); + } + + public function testTitle() + { + $project = new Project(); + + $result = $project->setTitle('title'); + self::assertEquals(true, $result); + self::assertEquals('title', $project->getTitle()); + + $result = $project->setTitle('title'); + self::assertEquals(false, $result); + } + + public function testReference() + { + $project = new Project(); + + $result = $project->setReference('git://reference'); + self::assertEquals(true, $result); + self::assertEquals('git://reference', $project->getReference()); + + $result = $project->setReference('git://reference'); + self::assertEquals(false, $result); + } + + public function testBranch() + { + $project = new Project(); + + self::assertEquals('master', $project->getBranch()); + + $project->setType('hg'); + self::assertEquals('default', $project->getBranch()); + + $project->setType('svn'); + self::assertEquals('trunk', $project->getBranch()); + + $project = new Project(); + + $result = $project->setBranch('branch'); + self::assertEquals(true, $result); + self::assertEquals('branch', $project->getBranch()); + + $result = $project->setBranch('branch'); + self::assertEquals(false, $result); + } + + public function testDefaultBranchOnly() + { + $project = new Project(); + + $result = $project->setDefaultBranchOnly(true); + self::assertEquals(true, $result); + self::assertEquals(true, $project->getDefaultBranchOnly()); + + $result = $project->setDefaultBranchOnly(true); + self::assertEquals(false, $result); + } + + public function testSshPrivateKey() + { + $project = new Project(); + + $result = $project->setSshPrivateKey('private-key'); + self::assertEquals(true, $result); + self::assertEquals('private-key', $project->getSshPrivateKey()); + + $result = $project->setSshPrivateKey('private-key'); + self::assertEquals(false, $result); + } + + public function testSshPublicKey() + { + $project = new Project(); + + $result = $project->setSshPublicKey('public-key'); + self::assertEquals(true, $result); + self::assertEquals('public-key', $project->getSshPublicKey()); + + $result = $project->setSshPublicKey('public-key'); + self::assertEquals(false, $result); + } + + public function testType() + { + $project = new Project(); + + $result = $project->setType('git'); + self::assertEquals(true, $result); + self::assertEquals('git', $project->getType()); + + $result = $project->setType('git'); + self::assertEquals(false, $result); + } + + + public function testAccessInformation() + { + $project = new Project(); + + $result = $project->setAccessInformation(['key-1' => 'value-1', 'key-2' => 'value-2']); + self::assertEquals(true, $result); + self::assertEquals(['key-1' => 'value-1', 'key-2' => 'value-2'], $project->getAccessInformation()); + self::assertEquals('value-1', $project->getAccessInformation('key-1')); + self::assertEquals(null, $project->getAccessInformation('key-3')); + + $result = $project->setAccessInformation(['key-1' => 'value-1', 'key-2' => 'value-2']); + self::assertEquals(false, $result); + } + + public function testLastCommit() + { + $project = new Project(); + + $result = $project->setLastCommit('commit'); + self::assertEquals(true, $result); + self::assertEquals('commit', $project->getLastCommit()); + + $result = $project->setLastCommit('commit'); + self::assertEquals(false, $result); + } + + public function testBuildConfig() + { + $project = new Project(); + + $result = $project->setBuildConfig('config'); + self::assertEquals(true, $result); + self::assertEquals('config', $project->getBuildConfig()); + + $result = $project->setBuildConfig('config'); + self::assertEquals(false, $result); + } + + public function testAllowPublicStatus() + { + $project = new Project(); + + $result = $project->setAllowPublicStatus(true); + self::assertEquals(true, $result); + self::assertEquals(true, $project->getAllowPublicStatus()); + + $result = $project->setAllowPublicStatus(true); + self::assertEquals(false, $result); + } + + public function testArchived() + { + $project = new Project(); + + $result = $project->setArchived(true); + self::assertEquals(true, $result); + self::assertEquals(true, $project->getArchived()); + + $result = $project->setArchived(true); + self::assertEquals(false, $result); + } + + public function testGroupId() + { + $project = new Project(); + + $result = $project->setGroupId(200); + self::assertEquals(true, $result); + self::assertEquals(200, $project->getGroupId()); + + $result = $project->setGroupId(200); + self::assertEquals(false, $result); + } + + public function testCreateDate() + { + $project = new Project(); + self::assertEquals(null, $project->getCreateDate()); + + $project = new Project(); + $createDate = new \DateTime(); + + $result = $project->setCreateDate($createDate); + self::assertEquals(true, $result); + self::assertEquals($createDate->getTimestamp(), $project->getCreateDate()->getTimestamp()); + + $result = $project->setCreateDate($createDate); + self::assertEquals(false, $result); + } + + public function testUserId() + { + $project = new Project(); + + $result = $project->setUserId(300); + self::assertEquals(true, $result); + self::assertEquals(300, $project->getUserId()); + + $result = $project->setUserId(300); + self::assertEquals(false, $result); + } +} diff --git a/tests/src/Model/Base/UserTest.php b/tests/src/Model/Base/UserTest.php new file mode 100644 index 00000000..02766939 --- /dev/null +++ b/tests/src/Model/Base/UserTest.php @@ -0,0 +1,152 @@ + null, + 'email' => null, + 'hash' => null, + 'is_admin' => null, + 'name' => null, + 'language' => null, + 'per_page' => null, + 'provider_key' => null, + 'provider_data' => null, + 'remember_key' => null, + ], $user->getDataArray()); + } + + public function testId() + { + $user = new User(); + + $result = $user->setId(100); + self::assertEquals(true, $result); + self::assertEquals(100, $user->getId()); + + $result = $user->setId(100); + self::assertEquals(false, $result); + } + + public function testEmail() + { + $user = new User(); + + $result = $user->setEmail('email@email.com'); + self::assertEquals(true, $result); + self::assertEquals('email@email.com', $user->getEmail()); + + $result = $user->setEmail('email@email.com'); + self::assertEquals(false, $result); + } + + public function testHash() + { + $user = new User(); + + $result = $user->setHash('hash'); + self::assertEquals(true, $result); + self::assertEquals('hash', $user->getHash()); + + $result = $user->setHash('hash'); + self::assertEquals(false, $result); + } + + public function testIsAdmin() + { + $user = new User(); + + $result = $user->setIsAdmin(true); + self::assertEquals(true, $result); + self::assertEquals(true, $user->getIsAdmin()); + + $result = $user->setIsAdmin(true); + self::assertEquals(false, $result); + } + + public function testName() + { + $user = new User(); + + $result = $user->setName('name'); + self::assertEquals(true, $result); + self::assertEquals('name', $user->getName()); + + $result = $user->setName('name'); + self::assertEquals(false, $result); + } + + public function testLanguage() + { + $user = new User(); + + $result = $user->setLanguage('la'); + self::assertEquals(true, $result); + self::assertEquals('la', $user->getLanguage()); + + $result = $user->setLanguage('la'); + self::assertEquals(false, $result); + } + + public function testPerPage() + { + $user = new User(); + + $result = $user->setPerPage(10); + self::assertEquals(true, $result); + self::assertEquals(10, $user->getPerPage()); + + $result = $user->setPerPage(10); + self::assertEquals(false, $result); + } + + public function testProviderKey() + { + $user = new User(); + + $result = $user->setProviderKey('key'); + self::assertEquals(true, $result); + self::assertEquals('key', $user->getProviderKey()); + + $result = $user->setProviderKey('key'); + self::assertEquals(false, $result); + } + + public function testProviderData() + { + $user = new User(); + + $result = $user->setProviderData(['key-1' => 'value-1', 'key-2' => 'value-2']); + self::assertEquals(true, $result); + self::assertEquals(['key-1' => 'value-1', 'key-2' => 'value-2'], $user->getProviderData()); + self::assertEquals('value-1', $user->getProviderData('key-1')); + self::assertEquals(null, $user->getProviderData('key-3')); + + $result = $user->setProviderData(['key-1' => 'value-1', 'key-2' => 'value-2']); + self::assertEquals(false, $result); + } + + public function testRememberKey() + { + $user = new User(); + + $result = $user->setRememberKey('remember'); + self::assertEquals(true, $result); + self::assertEquals('remember', $user->getRememberKey()); + + $result = $user->setRememberKey('remember'); + self::assertEquals(false, $result); + } +} From 2ed6377971d52fdde25b37c58ab3c64a271c2b2d Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 11 Mar 2018 23:57:18 +0700 Subject: [PATCH 24/28] Removed useless field 'last_commit' from table 'project'. --- ...65225_removed_last_commit_from_project.php | 32 +++++++++++++++++++ src/Model/Base/Project.php | 28 ---------------- tests/src/Model/Base/ProjectTest.php | 13 -------- 3 files changed, 32 insertions(+), 41 deletions(-) create mode 100644 src/Migrations/20180311165225_removed_last_commit_from_project.php diff --git a/src/Migrations/20180311165225_removed_last_commit_from_project.php b/src/Migrations/20180311165225_removed_last_commit_from_project.php new file mode 100644 index 00000000..c19f254c --- /dev/null +++ b/src/Migrations/20180311165225_removed_last_commit_from_project.php @@ -0,0 +1,32 @@ +hasTable('project')) { + $table = $this->table('project'); + + if ($table->hasColumn('last_commit')) { + $table + ->removeColumn('last_commit') + ->save(); + } + } + } + + public function down() + { + if ($this->hasTable('project')) { + $table = $this->table('project'); + + if (!$table->hasColumn('last_commit')) { + $table + ->addColumn('last_commit', 'string', ['limit' => 250, 'null' => true, 'default' => null]) + ->save(); + } + } + } +} diff --git a/src/Model/Base/Project.php b/src/Model/Base/Project.php index 25f94154..0843ddb4 100644 --- a/src/Model/Base/Project.php +++ b/src/Model/Base/Project.php @@ -24,7 +24,6 @@ class Project extends Model 'ssh_public_key' => null, 'type' => null, 'access_information' => null, - 'last_commit' => null, 'build_config' => null, 'allow_public_status' => null, 'archived' => null, @@ -300,33 +299,6 @@ class Project extends Model return $this->setModified('access_information'); } - - /** - * @return string - */ - public function getLastCommit() - { - return $this->data['last_commit']; - } - - /** - * @param string $value - * - * @return boolean - */ - public function setLastCommit($value) - { - $this->validateString('last_commit', $value); - - if ($this->data['last_commit'] === $value) { - return false; - } - - $this->data['last_commit'] = $value; - - return $this->setModified('last_commit'); - } - /** * @return string */ diff --git a/tests/src/Model/Base/ProjectTest.php b/tests/src/Model/Base/ProjectTest.php index 6f8e2daa..8231afd2 100644 --- a/tests/src/Model/Base/ProjectTest.php +++ b/tests/src/Model/Base/ProjectTest.php @@ -24,7 +24,6 @@ class ProjectTest extends TestCase 'ssh_public_key' => null, 'type' => null, 'access_information' => null, - 'last_commit' => null, 'build_config' => null, 'allow_public_status' => null, 'archived' => null, @@ -155,18 +154,6 @@ class ProjectTest extends TestCase self::assertEquals(false, $result); } - public function testLastCommit() - { - $project = new Project(); - - $result = $project->setLastCommit('commit'); - self::assertEquals(true, $result); - self::assertEquals('commit', $project->getLastCommit()); - - $result = $project->setLastCommit('commit'); - self::assertEquals(false, $result); - } - public function testBuildConfig() { $project = new Project(); From 10d41dba815362b181b8dda9725cc7113975ff90 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 12 Mar 2018 00:34:48 +0700 Subject: [PATCH 25/28] Added constants for project types (git, hg, github...). --- src/BuildFactory.php | 19 +++++++------ src/Controller/ProjectController.php | 23 ++++++++-------- src/Controller/WebhookController.php | 41 ++++++++++++++++++++-------- src/Model/Base/Project.php | 34 +++++++++++++++++++++++ 4 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/BuildFactory.php b/src/BuildFactory.php index f217b295..3d66aa9c 100644 --- a/src/BuildFactory.php +++ b/src/BuildFactory.php @@ -2,6 +2,7 @@ namespace PHPCensor; +use PHPCensor\Model\Project; use PHPCensor\Store\Factory; use PHPCensor\Model\Build; @@ -41,31 +42,31 @@ class BuildFactory if (!empty($project)) { switch ($project->getType()) { - case 'local': + case Project::TYPE_LOCAL: $type = 'LocalBuild'; break; - case 'git': + case Project::TYPE_GIT: $type = 'GitBuild'; break; - case 'github': + case Project::TYPE_GITHUB: $type = 'GithubBuild'; break; - case 'bitbucket': + case Project::TYPE_BITBUCKET: $type = 'BitbucketBuild'; break; - case 'gitlab': + case Project::TYPE_GITLAB: $type = 'GitlabBuild'; break; - case 'gogs': + case Project::TYPE_GOGS: $type = 'GogsBuild'; break; - case 'hg': + case Project::TYPE_HG: $type = 'HgBuild'; break; - case 'bitbucket-hg': + case Project::TYPE_BITBUCKET_HG: $type = 'BitbucketHgBuild'; break; - case 'svn': + case Project::TYPE_SVN: $type = 'SvnBuild'; break; default: diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index 700f149b..25abafce 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -16,6 +16,7 @@ use PHPCensor\Model\Build; use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\View; use PHPCensor\Store\Factory; +use PHPCensor\Model\Project; /** * Project Controller - Allows users to create, edit and view projects. @@ -426,16 +427,16 @@ class ProjectController extends PHPCensor\Controller $form->addField(new Form\Element\Hidden('pubkey')); $options = [ - 'choose' => Lang::get('select_repository_type'), - 'github' => 'GitHub', - 'bitbucket' => 'Bitbucket (Git)', - 'bitbucket-hg' => 'Bitbucket (Hg)', - 'gitlab' => 'GitLab', - 'gogs' => 'Gogs', - 'git' => 'Git', - 'local' => Lang::get('local'), - 'hg' => 'Hg (Mercurial)', - 'svn' => 'Svn (Subversion)', + 'choose' => Lang::get('select_repository_type'), + Project::TYPE_GITHUB => 'GitHub', + Project::TYPE_BITBUCKET => 'Bitbucket (Git)', + Project::TYPE_BITBUCKET_HG => 'Bitbucket (Hg)', + Project::TYPE_GITLAB => 'GitLab', + Project::TYPE_GOGS => 'Gogs', + Project::TYPE_GIT => 'Git', + Project::TYPE_LOCAL => Lang::get('local'), + Project::TYPE_HG => 'Hg (Mercurial)', + Project::TYPE_SVN => 'Svn (Subversion)', ]; $field = Form\Element\Select::create('type', Lang::get('where_hosted'), true); @@ -566,7 +567,7 @@ class ProjectController extends PHPCensor\Controller if (in_array($type, $validators) && !preg_match($validators[$type]['regex'], $val)) { throw new \Exception($validators[$type]['message']); - } elseif ($type == 'local' && !is_dir($val)) { + } elseif (Project::TYPE_LOCAL === $type && !is_dir($val)) { throw new \Exception(Lang::get('error_path')); } diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index 7ffe654e..5888cb8f 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -99,7 +99,12 @@ class WebhookController extends Controller */ public function bitbucket($projectId) { - $project = $this->fetchProject($projectId, ['bitbucket', 'bitbucket-hg', 'hg', 'git']); + $project = $this->fetchProject($projectId, [ + Project::TYPE_BITBUCKET, + Project::TYPE_BITBUCKET_HG, + Project::TYPE_HG, + Project::TYPE_GIT, + ]); // Support both old services and new webhooks if ($payload = $this->getParam('payload')) { @@ -292,7 +297,10 @@ class WebhookController extends Controller */ public function git($projectId) { - $project = $this->fetchProject($projectId, ['local', 'git']); + $project = $this->fetchProject($projectId, [ + Project::TYPE_LOCAL, + Project::TYPE_GIT, + ]); $branch = $this->getParam('branch', $project->getBranch()); $commit = $this->getParam('commit'); $commitMessage = $this->getParam('message'); @@ -318,7 +326,10 @@ class WebhookController extends Controller */ public function github($projectId) { - $project = $this->fetchProject($projectId, ['github', 'git']); + $project = $this->fetchProject($projectId, [ + Project::TYPE_GITHUB, + Project::TYPE_GIT, + ]); switch ($_SERVER['CONTENT_TYPE']) { case 'application/json': @@ -503,7 +514,10 @@ class WebhookController extends Controller */ public function gitlab($projectId) { - $project = $this->fetchProject($projectId, ['gitlab', 'git']); + $project = $this->fetchProject($projectId, [ + Project::TYPE_GITLAB, + Project::TYPE_GIT, + ]); $payloadString = file_get_contents("php://input"); $payload = json_decode($payloadString, true); @@ -570,7 +584,9 @@ class WebhookController extends Controller */ public function svn($projectId) { - $project = $this->fetchProject($projectId, 'svn'); + $project = $this->fetchProject($projectId, [ + Project::TYPE_SVN + ]); $branch = $this->getParam('branch', $project->getBranch()); $commit = $this->getParam('commit'); $commitMessage = $this->getParam('message'); @@ -596,7 +612,11 @@ class WebhookController extends Controller */ public function gogs($projectId) { - $project = $this->fetchProject($projectId, ['gogs', 'git']); + $project = $this->fetchProject($projectId, [ + Project::TYPE_GOGS, + Project::TYPE_GIT, + ]); + switch ($_SERVER['CONTENT_TYPE']) { case 'application/json': $payload = json_decode(file_get_contents('php://input'), true); @@ -883,13 +903,13 @@ class WebhookController extends Controller * Fetch a project and check its type. * * @param integer $projectId id or title of project - * @param string $expectedType + * @param array $expectedType * * @return Project * * @throws Exception If the project does not exist or is not of the expected type. */ - protected function fetchProject($projectId, $expectedType) + protected function fetchProject($projectId, array $expectedType) { if (empty($projectId)) { throw new Exception('Project does not exist: ' . $projectId); @@ -908,10 +928,7 @@ class WebhookController extends Controller $project = reset($projects['items']); } - if (is_array($expectedType) - ? !in_array($project->getType(), $expectedType) - : $project->getType() !== $expectedType - ) { + if (!in_array($project->getType(), $expectedType, true)) { throw new Exception('Wrong project type: ' . $project->getType()); } diff --git a/src/Model/Base/Project.php b/src/Model/Base/Project.php index 0843ddb4..15e0c250 100644 --- a/src/Model/Base/Project.php +++ b/src/Model/Base/Project.php @@ -2,10 +2,21 @@ namespace PHPCensor\Model\Base; +use PHPCensor\Exception\HttpException\ValidationException; use PHPCensor\Model; class Project extends Model { + const TYPE_LOCAL = 'local'; + const TYPE_GIT = 'git'; + const TYPE_GITHUB = 'github'; + const TYPE_BITBUCKET = 'bitbucket'; + const TYPE_GITLAB = 'gitlab'; + const TYPE_GOGS = 'gogs'; + const TYPE_HG = 'hg'; + const TYPE_BITBUCKET_HG = 'bitbucket-hg'; + const TYPE_SVN = 'svn'; + /** * @var string */ @@ -32,6 +43,21 @@ class Project extends Model 'user_id' => 0, ]; + /** + * @var array + */ + protected $allowedTypes = [ + self::TYPE_LOCAL, + self::TYPE_GIT, + self::TYPE_GITHUB, + self::TYPE_BITBUCKET, + self::TYPE_GITLAB, + self::TYPE_GOGS, + self::TYPE_HG, + self::TYPE_BITBUCKET_HG, + self::TYPE_SVN, + ]; + /** * @return integer */ @@ -247,12 +273,20 @@ class Project extends Model * @param string $value * * @return boolean + * + * @throws ValidationException */ public function setType($value) { $this->validateNotNull('type', $value); $this->validateString('type', $value); + if (!in_array($value, $this->allowedTypes, true)) { + throw new ValidationException( + 'Column "type" must be one of: ' . join(', ', $this->allowedTypes) . '.' + ); + } + if ($this->data['type'] === $value) { return false; } From d3a390d3f89b5fb062f2f8ac8b5859a799a425ee Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 12 Mar 2018 19:51:41 +0700 Subject: [PATCH 26/28] Added status and source build fields validation. --- phpmd.xml | 2 +- src/Model/Base/Build.php | 39 ++++++++++++++++++++++++++++ tests/src/Model/Base/BuildTest.php | 6 +++++ tests/src/Model/Base/ProjectTest.php | 4 ++- tests/src/Model/ProjectTest.php | 10 +++++++ 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/phpmd.xml b/phpmd.xml index e7d9aa7c..b4e6ef61 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -21,7 +21,7 @@ - + diff --git a/src/Model/Base/Build.php b/src/Model/Base/Build.php index c1fc0cab..c356aa2b 100644 --- a/src/Model/Base/Build.php +++ b/src/Model/Base/Build.php @@ -2,6 +2,7 @@ namespace PHPCensor\Model\Base; +use PHPCensor\Exception\HttpException\ValidationException; use PHPCensor\Model; class Build extends Model @@ -40,6 +41,28 @@ class Build extends Model 'user_id' => 0, ]; + /** + * @var array + */ + protected $allowedStatuses = [ + self::STATUS_PENDING, + self::STATUS_RUNNING, + self::STATUS_SUCCESS, + self::STATUS_FAILED, + ]; + + /** + * @var array + */ + protected $allowedSources = [ + self::SOURCE_UNKNOWN, + self::SOURCE_MANUAL_WEB, + self::SOURCE_MANUAL_CONSOLE, + self::SOURCE_PERIODICAL, + self::SOURCE_WEBHOOK, + self::SOURCE_WEBHOOK_PULL_REQUEST, + ]; + /** * @return integer */ @@ -132,6 +155,8 @@ class Build extends Model /** * @param integer $value * + * @throws ValidationException + * * @return boolean */ public function setStatus($value) @@ -139,6 +164,12 @@ class Build extends Model $this->validateNotNull('status', $value); $this->validateInt('status', $value); + if (!in_array($value, $this->allowedStatuses, true)) { + throw new ValidationException( + 'Column "status" must be one of: ' . join(', ', $this->allowedStatuses) . '.' + ); + } + if ($this->data['status'] === $value) { return false; } @@ -443,12 +474,20 @@ class Build extends Model /** * @param integer $value * + * @throws ValidationException + * * @return boolean */ public function setSource($value) { $this->validateInt('source', $value); + if (!in_array($value, $this->allowedSources, true)) { + throw new ValidationException( + 'Column "source" must be one of: ' . join(', ', $this->allowedSources) . '.' + ); + } + if ($this->data['source'] === $value) { return false; } diff --git a/tests/src/Model/Base/BuildTest.php b/tests/src/Model/Base/BuildTest.php index 41785c88..db000c94 100644 --- a/tests/src/Model/Base/BuildTest.php +++ b/tests/src/Model/Base/BuildTest.php @@ -80,6 +80,9 @@ class BuildTest extends TestCase $result = $build->setStatus(Build::STATUS_FAILED); self::assertEquals(false, $result); + + self::expectException('\PHPCensor\Exception\HttpException\ValidationException'); + $build->setStatus(10); } public function testLog() @@ -226,6 +229,9 @@ class BuildTest extends TestCase $result = $build->setSource(Build::SOURCE_WEBHOOK_PULL_REQUEST); self::assertEquals(false, $result); + + self::expectException('\PHPCensor\Exception\HttpException\ValidationException'); + $build->setSource(20); } public function testUserId() diff --git a/tests/src/Model/Base/ProjectTest.php b/tests/src/Model/Base/ProjectTest.php index 8231afd2..de1ebc9b 100644 --- a/tests/src/Model/Base/ProjectTest.php +++ b/tests/src/Model/Base/ProjectTest.php @@ -137,8 +137,10 @@ class ProjectTest extends TestCase $result = $project->setType('git'); self::assertEquals(false, $result); - } + self::expectException('\PHPCensor\Exception\HttpException\ValidationException'); + $project->setType('invalid-type'); + } public function testAccessInformation() { diff --git a/tests/src/Model/ProjectTest.php b/tests/src/Model/ProjectTest.php index 267c058c..ef9eda58 100644 --- a/tests/src/Model/ProjectTest.php +++ b/tests/src/Model/ProjectTest.php @@ -2,6 +2,7 @@ namespace Tests\PHPCensor\Model; +use PHPCensor\Exception\HttpException\ValidationException; use PHPCensor\Model\Project; use PHPCensor\Model; @@ -16,6 +17,15 @@ class ProjectTest extends \PHPUnit\Framework\TestCase { $project = new Project(); self::assertTrue($project instanceof Model); + + try { + $project->setArchived('true'); + } catch (ValidationException $e) { + self::assertEquals( + 'Column "archived" must be a boolean.', + $e->getMessage() + ); + } } public function testExecute_TestGitDefaultBranch() From 7abd3febc195da7ab0f8a33aa3be34e89c7a639b Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 12 Mar 2018 22:58:12 +0700 Subject: [PATCH 27/28] Refactored Csrf form widget. + Added unit tests for Csrt. --- composer.json | 1 + composer.lock | 104 +++++++++++++++++++------- src/Controller/GroupController.php | 3 + src/Controller/ProjectController.php | 4 +- src/Controller/SessionController.php | 107 +++++++++++++-------------- src/Controller/UserController.php | 18 +++-- src/Form/Element/Csrf.php | 20 ++--- src/View/Form/Csrf.phtml | 2 +- tests/src/FormTest.php | 19 ++++- 9 files changed, 175 insertions(+), 103 deletions(-) diff --git a/composer.json b/composer.json index 90e36e05..24016281 100644 --- a/composer.json +++ b/composer.json @@ -81,6 +81,7 @@ "phploc/phploc": "~4.0.0", "jakub-onderka/php-parallel-lint": "~0.9.0", "sensiolabs/security-checker": "~4.0.0", + "paragonie/random_compat": "~2.0.0", "symfony/debug": "~3.4.0", "doctrine/instantiator": "~1.0.0", diff --git a/composer.lock b/composer.lock index 823538ba..11d3e97c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "88f485bcc21591dbaf905423dc70d835", + "content-hash": "8c2289ac491f1f1019f88be4f375b8a9", "packages": [ { "name": "behat/gherkin", @@ -1144,6 +1144,54 @@ "homepage": "http://www.oomphinc.com/", "time": "2017-03-31T16:57:39+00:00" }, + { + "name": "paragonie/random_compat", + "version": "v2.0.11", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/5da4d3c796c275c55f057af5a643ae297d96b4d8", + "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "pseudorandom", + "random" + ], + "time": "2017-09-27T21:40:39+00:00" + }, { "name": "pda/pheanstalk", "version": "v3.1.0", @@ -2091,16 +2139,16 @@ }, { "name": "psr/simple-cache", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/simple-cache.git", - "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24" + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/753fa598e8f3b9966c886fe13f370baa45ef0e24", - "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", "shasum": "" }, "require": { @@ -2135,7 +2183,7 @@ "psr-16", "simple-cache" ], - "time": "2017-01-02T13:31:39+00:00" + "time": "2017-10-23T01:57:42+00:00" }, { "name": "robmorgan/phinx", @@ -3029,7 +3077,7 @@ }, { "name": "symfony/browser-kit", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", @@ -3086,7 +3134,7 @@ }, { "name": "symfony/cache", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", @@ -3156,7 +3204,7 @@ }, { "name": "symfony/config", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/config.git", @@ -3219,7 +3267,7 @@ }, { "name": "symfony/console", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", @@ -3288,7 +3336,7 @@ }, { "name": "symfony/css-selector", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -3341,7 +3389,7 @@ }, { "name": "symfony/debug", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", @@ -3397,16 +3445,16 @@ }, { "name": "symfony/dependency-injection", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "752c45dc831dc42a472f0ab8ae0450b63b840656" + "reference": "12e901abc1cb0d637a0e5abe9923471361d96b07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/752c45dc831dc42a472f0ab8ae0450b63b840656", - "reference": "752c45dc831dc42a472f0ab8ae0450b63b840656", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/12e901abc1cb0d637a0e5abe9923471361d96b07", + "reference": "12e901abc1cb0d637a0e5abe9923471361d96b07", "shasum": "" }, "require": { @@ -3464,11 +3512,11 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2018-02-26T14:27:04+00:00" + "time": "2018-03-04T03:54:53+00:00" }, { "name": "symfony/dom-crawler", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", @@ -3524,7 +3572,7 @@ }, { "name": "symfony/event-dispatcher", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -3587,7 +3635,7 @@ }, { "name": "symfony/filesystem", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", @@ -3636,16 +3684,16 @@ }, { "name": "symfony/finder", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "6a615613745cef820d807443f32076bb9f5d0a38" + "reference": "a479817ce0a9e4adfd7d39c6407c95d97c254625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/6a615613745cef820d807443f32076bb9f5d0a38", - "reference": "6a615613745cef820d807443f32076bb9f5d0a38", + "url": "https://api.github.com/repos/symfony/finder/zipball/a479817ce0a9e4adfd7d39c6407c95d97c254625", + "reference": "a479817ce0a9e4adfd7d39c6407c95d97c254625", "shasum": "" }, "require": { @@ -3681,7 +3729,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2018-02-11T17:15:12+00:00" + "time": "2018-03-05T18:28:11+00:00" }, { "name": "symfony/polyfill-apcu", @@ -3800,7 +3848,7 @@ }, { "name": "symfony/process", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/process.git", @@ -3849,7 +3897,7 @@ }, { "name": "symfony/yaml", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", @@ -4004,7 +4052,7 @@ }, { "name": "symfony/var-dumper", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index 56744723..ae7a06e2 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -92,9 +92,12 @@ class GroupController extends Controller } $form = new Form(); + $form->setMethod('POST'); $form->setAction(APP_URL . 'group/edit' . (!is_null($groupId) ? '/' . $groupId : '')); + $form->addField(new Form\Element\Csrf('group_form')); + $title = new Form\Element\Text('title'); $title->setContainerClass('form-group'); $title->setClass('form-control'); diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index 25abafce..e1ceaafc 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -421,9 +421,9 @@ class ProjectController extends PHPCensor\Controller $form = new Form(); $form->setMethod('POST'); - $form->setAction(APP_URL.'project/' . $type); + $form->setAction(APP_URL . 'project/' . $type); - $form->addField(new Form\Element\Csrf('csrf')); + $form->addField(new Form\Element\Csrf('project_form')); $form->addField(new Form\Element\Hidden('pubkey')); $options = [ diff --git a/src/Controller/SessionController.php b/src/Controller/SessionController.php index 66b7ef12..a1a84241 100644 --- a/src/Controller/SessionController.php +++ b/src/Controller/SessionController.php @@ -2,6 +2,7 @@ namespace PHPCensor\Controller; +use PHPCensor\Form\Element\Csrf; use PHPCensor\Helper\Email; use PHPCensor\Helper\Lang; use PHPCensor\Controller; @@ -38,6 +39,44 @@ class SessionController extends Controller $this->authentication = Service::getInstance(); } + protected function loginForm($values) + { + $form = new \PHPCensor\Form(); + $form->setMethod('POST'); + $form->setAction(APP_URL . 'session/login'); + + $form->addField(new Csrf('login_form')); + + $email = new \PHPCensor\Form\Element\Text('email'); + $email->setLabel(Lang::get('login')); + $email->setRequired(true); + $email->setContainerClass('form-group'); + $email->setClass('form-control'); + $form->addField($email); + + $pwd = new \PHPCensor\Form\Element\Password('password'); + $pwd->setLabel(Lang::get('password')); + $pwd->setRequired(true); + $pwd->setContainerClass('form-group'); + $pwd->setClass('form-control'); + $form->addField($pwd); + + $remember = \PHPCensor\Form\Element\Checkbox::create('remember_me', Lang::get('remember_me'), false); + $remember->setContainerClass('form-group'); + $remember->setCheckedValue(1); + $remember->setValue(0); + $form->addField($remember); + + $pwd = new \PHPCensor\Form\Element\Submit(); + $pwd->setValue(Lang::get('log_in')); + $pwd->setClass('btn-success'); + $form->addField($pwd); + + $form->setValues($values); + + return $form; + } + /** * Handles user login (form and processing) */ @@ -55,15 +94,22 @@ class SessionController extends Controller } } + $method = $this->request->getMethod(); + + if ($method === 'POST') { + $values = $this->getParams(); + } else { + $values = []; + } + + $form = $this->loginForm($values); + $isLoginFailure = false; - if ($this->request->getMethod() == 'POST') { - $token = $this->getParam('token'); - if (!isset($token, $_SESSION['login_token']) || $token !== $_SESSION['login_token']) { + if ($this->request->getMethod() === 'POST') { + if (!$form->getChild('login_form')->validate()) { $isLoginFailure = true; } else { - unset($_SESSION['login_token']); - $email = $this->getParam('email'); $password = $this->getParam('password', ''); $rememberMe = (bool)$this->getParam('remember_me', 0); @@ -116,41 +162,6 @@ class SessionController extends Controller } } - $form = new \PHPCensor\Form(); - $form->setMethod('POST'); - $form->setAction(APP_URL . 'session/login'); - - $email = new \PHPCensor\Form\Element\Text('email'); - $email->setLabel(Lang::get('login')); - $email->setRequired(true); - $email->setContainerClass('form-group'); - $email->setClass('form-control'); - $form->addField($email); - - $pwd = new \PHPCensor\Form\Element\Password('password'); - $pwd->setLabel(Lang::get('password')); - $pwd->setRequired(true); - $pwd->setContainerClass('form-group'); - $pwd->setClass('form-control'); - $form->addField($pwd); - - $remember = \PHPCensor\Form\Element\Checkbox::create('remember_me', Lang::get('remember_me'), false); - $remember->setContainerClass('form-group'); - $remember->setCheckedValue(1); - $remember->setValue(0); - $form->addField($remember); - - $pwd = new \PHPCensor\Form\Element\Submit(); - $pwd->setValue(Lang::get('log_in')); - $pwd->setClass('btn-success'); - $form->addField($pwd); - - $tokenValue = $this->generateToken(); - $_SESSION['login_token'] = $tokenValue; - $token = new \PHPCensor\Form\Element\Hidden('token'); - $token->setValue($tokenValue); - $form->addField($token); - $this->view->form = $form->render(); $this->view->failed = $isLoginFailure; @@ -261,20 +272,4 @@ class SessionController extends Controller return $rtn; } - - /** Generate a random token. - * - * @return string - */ - protected function generateToken() - { - if (function_exists('openssl_random_pseudo_bytes')) { - return bin2hex(openssl_random_pseudo_bytes(16)); - } - - return sprintf("%04x", mt_rand(0, 0xFFFF)) - . sprintf("%04x", mt_rand(0, 0xFFFF)) - . sprintf("%04x", mt_rand(0, 0xFFFF)) - . sprintf("%04x", mt_rand(0, 0xFFFF)); - } } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index d50a6bc0..9381942a 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -84,9 +84,12 @@ class UserController extends Controller $this->layout->subtitle = Lang::get('edit_profile'); $form = new Form(); - $form->setAction(APP_URL.'user/profile'); + + $form->setAction(APP_URL . 'user/profile'); $form->setMethod('POST'); + $form->addField(new Form\Element\Csrf('profile_form')); + $name = new Form\Element\Text('name'); $name->setClass('form-control'); $name->setContainerClass('form-group'); @@ -159,15 +162,15 @@ class UserController extends Controller $method = $this->request->getMethod(); - if ($method == 'POST') { + if ($method === 'POST') { $values = $this->getParams(); } else { $values = []; } - $form = $this->userForm($values); + $form = $this->userForm($values); - if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { + if ($method !== 'POST' || ($method == 'POST' && !$form->validate())) { $view = new View('User/edit'); $view->type = 'add'; $view->user = null; @@ -236,9 +239,11 @@ class UserController extends Controller protected function userForm($values, $type = 'add') { $form = new Form(); + $form->setMethod('POST'); - $form->setAction(APP_URL.'user/' . $type); - $form->addField(new Form\Element\Csrf('csrf')); + $form->setAction(APP_URL . 'user/' . $type); + + $form->addField(new Form\Element\Csrf('user_form')); $field = new Form\Element\Email('email'); $field->setRequired(true); @@ -281,6 +286,7 @@ class UserController extends Controller $form->addField($field); $form->setValues($values); + return $form; } diff --git a/src/Form/Element/Csrf.php b/src/Form/Element/Csrf.php index a6c4ce7a..2d7951a0 100644 --- a/src/Form/Element/Csrf.php +++ b/src/Form/Element/Csrf.php @@ -6,17 +6,16 @@ use PHPCensor\View; class Csrf extends Hidden { - /** - * @var integer - */ - protected $rows = 4; - /** * @return boolean */ public function validate() { - if ($this->value != $_COOKIE[$this->getName()]) { + $sessionToken = isset($_SESSION['csrf_tokens'][$this->getName()]) + ? $_SESSION['csrf_tokens'][$this->getName()] + : null; + + if ($this->value !== $sessionToken) { return false; } @@ -30,9 +29,12 @@ class Csrf extends Hidden { parent::onPreRender($view); - $csrf = md5(microtime(true)); - $view->csrf = $csrf; + $this->setValue( + rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '=') + ); - setcookie($this->getName(), $csrf); + $view->value = $this->getValue(); + + $_SESSION['csrf_tokens'][$this->getName()] = $this->getValue(); } } diff --git a/src/View/Form/Csrf.phtml b/src/View/Form/Csrf.phtml index 3068e4f6..ae27cc6a 100644 --- a/src/View/Form/Csrf.phtml +++ b/src/View/Form/Csrf.phtml @@ -1 +1 @@ - + diff --git a/tests/src/FormTest.php b/tests/src/FormTest.php index 0344b8e1..ee66f04e 100755 --- a/tests/src/FormTest.php +++ b/tests/src/FormTest.php @@ -107,7 +107,7 @@ class FormTest extends \PHPUnit\Framework\TestCase public function testFieldSetBasics() { - $f = new Form\FieldSet(); + $f = new Form\FieldSet(); $f2 = new Form\FieldSet('group'); $f3 = new Form\FieldSet(); @@ -141,6 +141,14 @@ class FormTest extends \PHPUnit\Framework\TestCase $html = $f->render(); self::assertTrue(strpos($html, 'one') !== false); self::assertTrue(strpos($html, 'two') !== false); + + $children = $f->getChildren(); + self::assertEquals(2, count($children)); + self::assertEquals($f2, $children[$f2->getName()]); + self::assertEquals($f3, $children[$f3->getName()]); + + $child = $f->getChild($f3->getName()); + self::assertEquals($f3, $child); } public function testElements() @@ -196,6 +204,15 @@ class FormTest extends \PHPUnit\Framework\TestCase $e = new Form\Element\Url(); self::assertTrue(strpos($e->render(), 'url') !== false); + $_SESSION = []; + + $e = new Form\Element\Csrf(); + self::assertTrue(strpos($e->render(), $e->getValue()) !== false); + self::assertEquals($_SESSION['csrf_tokens'][$e->getName()], $e->getValue()); + self::assertTrue($e->validate()); + $e->setValue('111'); + self::assertFalse($e->validate()); + $e = new Form\Element\Password(); self::assertTrue(strpos($e->render(), 'password') !== false); } From ba0d9f14fa65f19755451594fc31cbb049bed696 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 13 Mar 2018 20:09:54 +0700 Subject: [PATCH 28/28] Refactored Controllers. --- src/Application.php | 67 +--- src/Controller.php | 167 ++------- src/Controller/BuildController.php | 14 +- src/Controller/BuildStatusController.php | 47 ++- src/Controller/GroupController.php | 14 +- src/Controller/HomeController.php | 9 +- src/Controller/ProjectController.php | 40 +- src/Controller/SessionController.php | 11 +- src/Controller/UserController.php | 17 +- src/Controller/WebhookController.php | 14 +- .../WidgetAllProjectsController.php | 18 +- .../WidgetBuildErrorsController.php | 18 +- src/Controller/WidgetLastBuildsController.php | 18 +- src/Http/Response.php | 15 - src/Http/Response/JsonResponse.php | 5 - src/Http/Response/RedirectResponse.php | 5 - src/View/BuildStatus/view.phtml | 350 ++++++++---------- src/View/layoutPublic.phtml | 43 +++ .../{Session.phtml => layoutSession.phtml} | 0 src/WebController.php | 152 ++++++++ 20 files changed, 512 insertions(+), 512 deletions(-) create mode 100644 src/View/layoutPublic.phtml rename src/View/{Session.phtml => layoutSession.phtml} (100%) create mode 100644 src/WebController.php diff --git a/src/Application.php b/src/Application.php index 3855e815..f726ec38 100644 --- a/src/Application.php +++ b/src/Application.php @@ -21,7 +21,7 @@ class Application protected $route; /** - * @var Controller + * @var Controller|WebController */ protected $controller; @@ -30,11 +30,6 @@ class Application */ protected $request; - /** - * @var Response - */ - protected $response; - /** * @var Config */ @@ -53,7 +48,6 @@ class Application public function __construct(Config $config, Request $request = null) { $this->config = $config; - $this->response = new Response(); if (!is_null($request)) { $this->request = $request; @@ -128,8 +122,9 @@ class Application if (!empty($this->route['callback'])) { $callback = $this->route['callback']; - if (!$callback($this->route, $this->response)) { - return $this->response; + $response = new Response(); + if (!$callback($this->route, $response)) { + return $response; } } @@ -153,33 +148,30 @@ class Application public function handleRequest() { try { - $this->response = $this->handleRequestInner(); + $response = $this->handleRequestInner(); } catch (HttpException $ex) { $this->config->set('page_title', 'Error'); $view = new View('exception'); $view->exception = $ex; - $this->response->setResponseCode($ex->getErrorCode()); - $this->response->setContent($view->render()); + $response = new Response(); + + $response->setResponseCode($ex->getErrorCode()); + $response->setContent($view->render()); } catch (\Exception $ex) { $this->config->set('page_title', 'Error'); $view = new View('exception'); $view->exception = $ex; - $this->response->setResponseCode(500); - $this->response->setContent($view->render()); + $response = new Response(); + + $response->setResponseCode(500); + $response->setContent($view->render()); } - if ($this->response->hasLayout() && $this->controller && $this->controller->layout) { - $this->setLayoutVariables($this->controller->layout); - - $this->controller->layout->content = $this->response->getContent(); - $this->response->setContent($this->controller->layout->render()); - } - - return $this->response; + return $response; } /** @@ -192,40 +184,13 @@ class Application protected function loadController($class) { /** @var Controller $controller */ - $controller = new $class($this->config, $this->request, $this->response); + $controller = new $class($this->config, $this->request); + $controller->init(); - $controller->layout = new View('layout'); - $controller->layout->title = 'PHP Censor'; - $controller->layout->breadcrumb = []; - $controller->layout->version = trim(file_get_contents(ROOT_DIR . 'VERSION.md')); - return $controller; } - /** - * Injects variables into the layout before rendering it. - * - * @param View $layout - */ - protected function setLayoutVariables(View &$layout) - { - $groups = []; - $groupStore = Factory::getStore('ProjectGroup'); - $groupList = $groupStore->getWhere([], 100, 0, ['title' => 'ASC']); - - foreach ($groupList['items'] as $group) { - $thisGroup = ['title' => $group->getTitle()]; - $projects = Factory::getStore('Project')->getByGroupId($group->getId(), false); - $thisGroup['projects'] = $projects['items']; - $groups[] = $thisGroup; - } - - $archivedProjects = Factory::getStore('Project')->getAll(true); - $layout->archived_projects = $archivedProjects['items']; - $layout->groups = $groups; - } - /** * Check whether we should skip auth (because it is disabled) * diff --git a/src/Controller.php b/src/Controller.php index f30854ad..0ceb1f03 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -2,171 +2,35 @@ namespace PHPCensor; -use PHPCensor\Exception\HttpException\ForbiddenException; use PHPCensor\Http\Request; use PHPCensor\Http\Response; -use PHPCensor\Store\Factory; -use PHPCensor\Model\User; -use PHPCensor\Store\UserStore; -class Controller +abstract class Controller { /** * @var Request */ protected $request; - /** - * @var Response - */ - protected $response; - /** * @var Config */ protected $config; /** - * @var View + * @param Config $config + * @param Request $request */ - protected $controllerView; - - /** - * @var View - */ - protected $view; - - /** - * @var string - */ - protected $className; - - /** - * @var View - */ - public $layout; + public function __construct(Config $config, Request $request) + { + $this->config = $config; + $this->request = $request; + } /** * Initialise the controller. */ - public function init() - { - // Extended by actual controllers. - } - - /** - * @param Config $config - * @param Request $request - * @param Response $response - */ - public function __construct(Config $config, Request $request, Response $response) - { - $this->config = $config; - $this->request = $request; - $this->response = $response; - - $class = explode('\\', get_class($this)); - $this->className = substr(array_pop($class), 0, -10); - $this->setControllerView(); - - if (!empty($_SESSION['php-censor-user'])) { - unset($_SESSION['php-censor-user']); - } - } - - /** - * Set the view that this controller should use. - */ - protected function setControllerView() - { - if (View::exists($this->className)) { - $this->controllerView = new View($this->className); - } else { - $this->controllerView = new View('{@content}'); - } - } - - /** - * Set the view that this controller action should use. - * - * @param string $action - */ - protected function setView($action) - { - if (View::exists($this->className . '/' . $action)) { - $this->view = new View($this->className . '/' . $action); - } - } - - /** - * Handle the incoming request. - * - * @param string $action - * @param array $actionParams - * - * @return Response - */ - public function handleAction($action, $actionParams) - { - $this->setView($action); - $response = call_user_func_array([$this, $action], $actionParams); - - if ($response instanceof Response) { - return $response; - } - - if (is_string($response)) { - $this->controllerView->content = $response; - } elseif (isset($this->view)) { - $this->controllerView->content = $this->view->render(); - } - - $this->response->setContent($this->controllerView->render()); - - return $this->response; - } - - /** - * Require that the currently logged in user is an administrator. - * - * @throws ForbiddenException - */ - protected function requireAdmin() - { - if (!$this->currentUserIsAdmin()) { - throw new ForbiddenException('You do not have permission to do that.'); - } - } - - /** - * Check if the currently logged in user is an administrator. - * - * @return boolean - */ - protected function currentUserIsAdmin() - { - $user = $this->getUser(); - if (!$user) { - return false; - } - - return $this->getUser()->getIsAdmin(); - } - - /** - * @return User|null - */ - protected function getUser() - { - if (empty($_SESSION['php-censor-user-id'])) { - return null; - } - - /** @var UserStore $userStore */ - $userStore = Factory::getStore('User'); - - return $userStore->getById($_SESSION['php-censor-user-id']); - } + abstract public function init(); /** * @param string $name @@ -186,6 +50,19 @@ class Controller return false; } + /** + * Handles an action on this controller and returns a Response object. + * + * @param string $action + * @param array $actionParams + * + * @return Response + */ + public function handleAction($action, $actionParams) + { + return call_user_func_array([$this, $action], $actionParams); + } + /** * Get a hash of incoming request parameters ($_GET, $_POST) * diff --git a/src/Controller/BuildController.php b/src/Controller/BuildController.php index 20176c38..3db8143b 100644 --- a/src/Controller/BuildController.php +++ b/src/Controller/BuildController.php @@ -12,7 +12,7 @@ use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\Build; use PHPCensor\Model\User; use PHPCensor\Service\BuildService; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\View; use PHPCensor\Store\Factory; @@ -21,8 +21,13 @@ use PHPCensor\Store\Factory; * * @author Dan Cryer */ -class BuildController extends Controller +class BuildController extends WebController { + /** + * @var string + */ + public $layoutName = 'layout'; + /** * @var \PHPCensor\Store\BuildStore */ @@ -33,11 +38,10 @@ class BuildController extends Controller */ protected $buildService; - /** - * Initialise the controller, set up stores and services. - */ public function init() { + parent::init(); + $this->buildStore = Factory::getStore('Build'); $this->buildService = new BuildService($this->buildStore); } diff --git a/src/Controller/BuildStatusController.php b/src/Controller/BuildStatusController.php index 23d376f9..60598c54 100644 --- a/src/Controller/BuildStatusController.php +++ b/src/Controller/BuildStatusController.php @@ -10,27 +10,33 @@ use PHPCensor\BuildFactory; use PHPCensor\Model\Project; use PHPCensor\Model\Build; use PHPCensor\Service\BuildStatusService; -use PHPCensor\Controller; +use PHPCensor\WebController; /** * Build Status Controller - Allows external access to build status information / images. * * @author Dan Cryer */ -class BuildStatusController extends Controller +class BuildStatusController extends WebController { - /* @var \PHPCensor\Store\ProjectStore */ - protected $projectStore; - - /* @var \PHPCensor\Store\BuildStore */ - protected $buildStore; + /** + * @var string + */ + public $layoutName = 'layoutPublic'; /** - * Initialise the controller, set up stores and services. + * @var \PHPCensor\Store\ProjectStore */ + protected $projectStore; + + /** + * @var \PHPCensor\Store\BuildStore + */ + protected $buildStore; + public function init() { - $this->response->disableLayout(); + parent::init(); $this->buildStore = Factory::getStore('Build'); $this->projectStore = Factory::getStore('Project'); @@ -74,7 +80,7 @@ class BuildStatusController extends Controller * * @param $projectId * - * @return bool + * @return Response * * @throws \Exception */ @@ -114,16 +120,16 @@ class BuildStatusController extends Controller /** * @param \SimpleXMLElement $xml * - * @return boolean + * @return Response */ protected function renderXml(\SimpleXMLElement $xml = null) { - $this->response->setHeader('Content-Type', 'text/xml'); - $this->response->setContent($xml->asXML()); - $this->response->flush(); - echo $xml->asXML(); + $response = new Response(); - return true; + $response->setHeader('Content-Type', 'text/xml'); + $response->setContent($xml->asXML()); + + return $response; } /** @@ -179,11 +185,12 @@ class BuildStatusController extends Controller $image = file_get_contents($cacheFile); - $this->response->disableLayout(); - $this->response->setHeader('Content-Type', 'image/svg+xml'); - $this->response->setContent($image); + $response = new Response(); - return $this->response; + $response->setHeader('Content-Type', 'image/svg+xml'); + $response->setContent($image); + + return $response; } /** diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index ae7a06e2..6fa13bfd 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -3,7 +3,7 @@ namespace PHPCensor\Controller; use PHPCensor\Form; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\ProjectGroup; use PHPCensor\Helper\Lang; @@ -15,18 +15,22 @@ use PHPCensor\Store\Factory; * * @author Dan Cryer */ -class GroupController extends Controller +class GroupController extends WebController { + /** + * @var string + */ + public $layoutName = 'layout'; + /** * @var \PHPCensor\Store\ProjectGroupStore */ protected $groupStore; - /** - * Set up this controller. - */ public function init() { + parent::init(); + $this->groupStore = Factory::getStore('ProjectGroup'); } diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 2ee3dca8..f65c0d6a 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -4,13 +4,18 @@ namespace PHPCensor\Controller; use PHPCensor\Config; use PHPCensor\Helper\Lang; -use PHPCensor\Controller; +use PHPCensor\WebController; /** * Home Controller - Displays the Dashboard. */ -class HomeController extends Controller +class HomeController extends WebController { + /** + * @var string + */ + public $layoutName = 'layout'; + /** * Display dashboard: */ diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index e1ceaafc..3d9a7d9b 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -17,14 +17,20 @@ use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\View; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; +use PHPCensor\WebController; /** * Project Controller - Allows users to create, edit and view projects. * * @author Dan Cryer */ -class ProjectController extends PHPCensor\Controller +class ProjectController extends WebController { + /** + * @var string + */ + public $layoutName = 'layout'; + /** * @var \PHPCensor\Store\ProjectStore */ @@ -50,6 +56,8 @@ class ProjectController extends PHPCensor\Controller */ public function init() { + parent::init(); + $this->buildStore = Factory::getStore('Build'); $this->projectStore = Factory::getStore('Project'); $this->projectService = new ProjectService($this->projectStore); @@ -69,10 +77,10 @@ class ProjectController extends PHPCensor\Controller $perPage = (integer)$this->getParam('per_page', 10); $builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage); - $this->response->disableLayout(); - $this->response->setContent($builds[0]); + $response = new PHPCensor\Http\Response(); + $response->setContent($builds[0]); - return $this->response; + return $response; } /** @@ -327,10 +335,10 @@ class ProjectController extends PHPCensor\Controller 'ssh_private_key' => $this->getParam('key', null), 'ssh_public_key' => $this->getParam('pubkey', null), 'build_config' => $this->getParam('build_config', null), - 'allow_public_status' => $this->getParam('allow_public_status', 0), + 'allow_public_status' => (boolean)$this->getParam('allow_public_status', 0), 'branch' => $this->getParam('branch', null), - 'default_branch_only' => $this->getParam('default_branch_only', 0), - 'group' => $this->getParam('group_id', null), + 'default_branch_only' => (boolean)$this->getParam('default_branch_only', 0), + 'group' => (integer)$this->getParam('group_id', null), 'environments' => $this->getParam('environments', null), ]; @@ -380,11 +388,11 @@ class ProjectController extends PHPCensor\Controller $form = $this->projectForm($values, 'edit/' . $projectId); if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { - $view = new View('Project/edit'); - $view->type = 'edit'; - $view->project = $project; - $view->form = $form; - $view->key = $values['pubkey']; + $view = new View('Project/edit'); + $view->type = 'edit'; + $view->project = $project; + $view->form = $form; + $view->key = $values['pubkey']; return $view->render(); } @@ -397,11 +405,11 @@ class ProjectController extends PHPCensor\Controller 'ssh_private_key' => $this->getParam('key', null), 'ssh_public_key' => $this->getParam('pubkey', null), 'build_config' => $this->getParam('build_config', null), - 'allow_public_status' => $this->getParam('allow_public_status', false), - 'archived' => $this->getParam('archived', false), + 'allow_public_status' => (boolean)$this->getParam('allow_public_status', false), + 'archived' => (boolean)$this->getParam('archived', false), 'branch' => $this->getParam('branch', null), - 'default_branch_only' => $this->getParam('default_branch_only', false), - 'group' => $this->getParam('group_id', null), + 'default_branch_only' => (boolean)$this->getParam('default_branch_only', false), + 'group' => (integer)$this->getParam('group_id', null), 'environments' => $this->getParam('environments', null), ]; diff --git a/src/Controller/SessionController.php b/src/Controller/SessionController.php index a1a84241..fdc5c936 100644 --- a/src/Controller/SessionController.php +++ b/src/Controller/SessionController.php @@ -5,7 +5,7 @@ namespace PHPCensor\Controller; use PHPCensor\Form\Element\Csrf; use PHPCensor\Helper\Email; use PHPCensor\Helper\Lang; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Security\Authentication\Service; use PHPCensor\Store\UserStore; @@ -16,8 +16,13 @@ use PHPCensor\Store\Factory; * * @author Dan Cryer */ -class SessionController extends Controller +class SessionController extends WebController { + /** + * @var string + */ + public $layoutName = 'layoutSession'; + /** * @var UserStore */ @@ -33,7 +38,7 @@ class SessionController extends Controller */ public function init() { - $this->response->disableLayout(); + parent::init(); $this->userStore = Factory::getStore('User'); $this->authentication = Service::getInstance(); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 9381942a..1fc0597e 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -5,7 +5,7 @@ namespace PHPCensor\Controller; use PHPCensor\Config; use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Form; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\Helper\Lang; use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\User; @@ -18,8 +18,13 @@ use PHPCensor\Store\Factory; * * @author Dan Cryer */ -class UserController extends Controller +class UserController extends WebController { + /** + * @var string + */ + public $layoutName = 'layout'; + /** * @var \PHPCensor\Store\UserStore */ @@ -35,6 +40,8 @@ class UserController extends Controller */ public function init() { + parent::init(); + $this->userStore = Factory::getStore('User'); $this->userService = new UserService($this->userStore); } @@ -70,7 +77,7 @@ class UserController extends Controller $language = null; } - $perPage = $this->getParam('per_page', null); + $perPage = (integer)$this->getParam('per_page', null); if (!$perPage) { $perPage = null; } @@ -183,7 +190,7 @@ class UserController extends Controller $name = $this->getParam('name', null); $email = $this->getParam('email', null); $password = $this->getParam('password', null); - $isAdmin = (int)$this->getParam('is_admin', 0); + $isAdmin = (boolean)$this->getParam('is_admin', 0); $this->userService->createUser($name, $email, 'internal', ['type' => 'internal'], $password, $isAdmin); @@ -224,7 +231,7 @@ class UserController extends Controller $name = $this->getParam('name', null); $email = $this->getParam('email', null); $password = $this->getParam('password', null); - $isAdmin = (int)$this->getParam('is_admin', 0); + $isAdmin = (boolean)$this->getParam('is_admin', 0); $this->userService->updateUser($user, $name, $email, $password, $isAdmin); diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index 5888cb8f..e810479c 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -43,18 +43,6 @@ class WebhookController extends Controller */ protected $buildService; - /** - * @param Config $config - * @param Request $request - * @param Response $response - */ - public function __construct(Config $config, Request $request, Response $response) - { - $this->config = $config; - $this->request = $request; - $this->response = $response; - } - /** * Initialise the controller, set up stores and services. */ @@ -77,7 +65,7 @@ class WebhookController extends Controller { $response = new Response\JsonResponse(); try { - $data = call_user_func_array([$this, $action], $actionParams); + $data = parent::handleAction($action, $actionParams); if (isset($data['responseCode'])) { $response->setResponseCode($data['responseCode']); unset($data['responseCode']); diff --git a/src/Controller/WidgetAllProjectsController.php b/src/Controller/WidgetAllProjectsController.php index 0ddcac50..48822749 100644 --- a/src/Controller/WidgetAllProjectsController.php +++ b/src/Controller/WidgetAllProjectsController.php @@ -3,7 +3,7 @@ namespace PHPCensor\Controller; use PHPCensor\Model\Build; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\Store\Factory; use PHPCensor\View; use PHPCensor\Model\Project; @@ -15,7 +15,7 @@ use PHPCensor\Store\ProjectGroupStore; /** * Widget All Projects Controller */ -class WidgetAllProjectsController extends Controller +class WidgetAllProjectsController extends WebController { /** * @var BuildStore @@ -37,6 +37,8 @@ class WidgetAllProjectsController extends Controller */ public function init() { + parent::init(); + $this->buildStore = Factory::getStore('Build'); $this->projectStore = Factory::getStore('Project'); $this->groupStore = Factory::getStore('ProjectGroup'); @@ -49,10 +51,10 @@ class WidgetAllProjectsController extends Controller { $this->view->groups = $this->getGroupInfo(); - $this->response->disableLayout(); - $this->response->setContent($this->view->render()); + $response = new Response(); + $response->setContent($this->view->render()); - return $this->response; + return $response; } /** @@ -142,9 +144,9 @@ class WidgetAllProjectsController extends Controller $this->view->failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); $this->view->counts = $counts; - $this->response->disableLayout(); - $this->response->setContent($this->view->render()); + $response = new Response(); + $response->setContent($this->view->render()); - return $this->response; + return $response; } } diff --git a/src/Controller/WidgetBuildErrorsController.php b/src/Controller/WidgetBuildErrorsController.php index 81bf2c33..706bf601 100644 --- a/src/Controller/WidgetBuildErrorsController.php +++ b/src/Controller/WidgetBuildErrorsController.php @@ -5,14 +5,14 @@ namespace PHPCensor\Controller; use PHPCensor\Store\Factory; use PHPCensor\View; use PHPCensor\Http\Response; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\Store\BuildStore; use PHPCensor\Store\ProjectStore; /** * Widget Build Errors Controller */ -class WidgetBuildErrorsController extends Controller +class WidgetBuildErrorsController extends WebController { /** * @var BuildStore @@ -29,6 +29,8 @@ class WidgetBuildErrorsController extends Controller */ public function init() { + parent::init(); + $this->buildStore = Factory::getStore('Build'); $this->projectStore = Factory::getStore('Project'); } @@ -42,10 +44,10 @@ class WidgetBuildErrorsController extends Controller $this->view->projects = $this->renderAllProjectsLatestBuilds($view); - $this->response->disableLayout(); - $this->response->setContent($this->view->render()); + $response = new Response(); + $response->setContent($this->view->render()); - return $this->response; + return $response; } /** @@ -53,10 +55,10 @@ class WidgetBuildErrorsController extends Controller */ public function update() { - $this->response->disableLayout(); - $this->response->setContent($this->renderAllProjectsLatestBuilds($this->view)); + $response = new Response(); + $response->setContent($this->renderAllProjectsLatestBuilds($this->view)); - return $this->response; + return $response; } /** diff --git a/src/Controller/WidgetLastBuildsController.php b/src/Controller/WidgetLastBuildsController.php index 3f178018..a2d48e24 100644 --- a/src/Controller/WidgetLastBuildsController.php +++ b/src/Controller/WidgetLastBuildsController.php @@ -6,13 +6,13 @@ use PHPCensor\Store\Factory; use PHPCensor\View; use PHPCensor\Http\Response; use PHPCensor\BuildFactory; -use PHPCensor\Controller; +use PHPCensor\WebController; use PHPCensor\Store\BuildStore; /** * Widget Last Builds Controller */ -class WidgetLastBuildsController extends Controller +class WidgetLastBuildsController extends WebController { /** * @var BuildStore @@ -24,6 +24,8 @@ class WidgetLastBuildsController extends Controller */ public function init() { + parent::init(); + $this->buildStore = Factory::getStore('Build'); } @@ -43,10 +45,10 @@ class WidgetLastBuildsController extends Controller $view->builds = $builds; $this->view->timeline = $view->render(); - $this->response->disableLayout(); - $this->response->setContent($this->view->render()); + $response = new Response(); + $response->setContent($this->view->render()); - return $this->response; + return $response; } /** @@ -62,9 +64,9 @@ class WidgetLastBuildsController extends Controller $this->view->builds = $builds; - $this->response->disableLayout(); - $this->response->setContent($this->view->render()); + $response = new Response(); + $response->setContent($this->view->render()); - return $this->response; + return $response; } } diff --git a/src/Http/Response.php b/src/Http/Response.php index 952e63ab..29e29ec6 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -13,21 +13,6 @@ class Response } } - public function hasLayout() - { - return !isset($this->data['layout']) ? true : $this->data['layout']; - } - - public function disableLayout() - { - $this->data['layout'] = false; - } - - public function enableLayout() - { - $this->data['layout'] = true; - } - public function getData() { return $this->data; diff --git a/src/Http/Response/JsonResponse.php b/src/Http/Response/JsonResponse.php index 81b4c141..7310710a 100644 --- a/src/Http/Response/JsonResponse.php +++ b/src/Http/Response/JsonResponse.php @@ -14,11 +14,6 @@ class JsonResponse extends Response $this->setHeader('Content-Type', 'application/json'); } - public function hasLayout() - { - return false; - } - protected function flushBody() { if (isset($this->data['body'])) { diff --git a/src/Http/Response/RedirectResponse.php b/src/Http/Response/RedirectResponse.php index 0174826d..b4c8f3d5 100644 --- a/src/Http/Response/RedirectResponse.php +++ b/src/Http/Response/RedirectResponse.php @@ -14,11 +14,6 @@ class RedirectResponse extends Response $this->setResponseCode(302); } - public function hasLayout() - { - return false; - } - public function flush() { parent::flush(); diff --git a/src/View/BuildStatus/view.phtml b/src/View/BuildStatus/view.phtml index 92e50371..74d8cbe9 100644 --- a/src/View/BuildStatus/view.phtml +++ b/src/View/BuildStatus/view.phtml @@ -1,207 +1,161 @@ - - - - <?= $project->getTitle(); ?> - PHP Censor + - + assets/vendor/admin-lte/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> - - - + $statusClass = null; + $statusText = null; - - + switch ($latest->getStatus()) { + case 0: + $statusClass = 'blue'; + $statusText = 'Pending'; + break; + case 1: + $statusClass = 'yellow'; + $statusText = 'Running'; + break; + case 2: + $statusClass = 'green'; + $statusText = 'Success'; + break; + case 3: + $statusClass = 'red'; + $statusText = 'Failed'; + break; + } - - - - - - -

    -
    - -
    -
    -
    -
    - + ?> - "> +
    +

    + getProject()->getTitle(); ?> #getId(); ?> () +

    +

    + getCommitMessage()); ?> + +

    + - $statusClass = null; - $statusText = null; + Branch: getBranch(); ?>
    + Committer: getCommitterEmail(); ?> - switch ($latest->getStatus()) { - case 0: - $statusClass = 'blue'; - $statusText = 'Pending'; - break; - case 1: - $statusClass = 'yellow'; - $statusText = 'Running'; - break; - case 2: - $statusClass = 'green'; - $statusText = 'Success'; - break; - case 3: - $statusClass = 'red'; - $statusText = 'Failed'; - break; - } - - ?> - -

    -
    -

    - getProject()->getTitle(); ?> #getId(); ?> () -

    -

    - getCommitMessage()); ?> - -

    - - - Branch: getBranch(); ?>
    - Committer: getCommitterEmail(); ?> - - getCommitId())): ?> -
    Commit: getCommitId(); ?>
    - -

    -
    -
    - -
    -
    -
    - - -
    -

    Builds

    - - - - - - - - - - - - - - - - - - - - - - - - getStatus()) - { - case 0: - $class = 'info'; - $status = 'Pending'; - - break; - - case 1: - $class = 'warning'; - $status = 'Running'; - break; - - case 2: - $class = 'success'; - $status = 'Success'; - break; - - case 3: - $class = 'danger'; - $status = 'Failed'; - break; - } - ?> - - - - - - - - - - - - - - -
    IDStatusDateCommitBranchEnvironmentDuration
    No builds yet.
    #getId(), 6, '0', STR_PAD_LEFT); ?> - - getCreateDate()->format('Y-m-d H:i:s'); ?> - getCommitId())) { - print sprintf( - '%s %s', - $build->getCommitLink(), - substr($build->getCommitId(), 0, 7), - $build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : '' - ); - } else { - print '—'; - } - ?> - - getSource()): ?> - - - getRemoteBranch(); ?> : - - - - - getBranch(); ?> - - getExtra('branches'); ?> - - getTag()): ?> / - - - - - - - getEnvironment(); - echo !empty($environment) ? $environment : '—' ; - ?> - - getDuration(); ?> sec. -
    -
    -
    -
    + getCommitId())): ?> +
    Commit: getCommitId(); ?>
    + +

    - +
    + +
    +
    - - + + +
    +

    Builds

    + + + + + + + + + + + + + + + + + + + + + + + + getStatus()) + { + case 0: + $class = 'info'; + $status = 'Pending'; + + break; + + case 1: + $class = 'warning'; + $status = 'Running'; + break; + + case 2: + $class = 'success'; + $status = 'Success'; + break; + + case 3: + $class = 'danger'; + $status = 'Failed'; + break; + } + ?> + + + + + + + + + + + + + + +
    IDStatusDateCommitBranchEnvironmentDuration
    No builds yet.
    #getId(), 6, '0', STR_PAD_LEFT); ?> + + getCreateDate()->format('Y-m-d H:i:s'); ?> + getCommitId())) { + print sprintf( + '%s %s', + $build->getCommitLink(), + substr($build->getCommitId(), 0, 7), + $build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : '' + ); + } else { + print '—'; + } + ?> + + getSource()): ?> + + + getRemoteBranch(); ?> : + + + + + getBranch(); ?> + + getExtra('branches'); ?> + + getTag()): ?> / + + + + + + + getEnvironment(); + echo !empty($environment) ? $environment : '—' ; + ?> + + getDuration(); ?> sec. +
    +
    diff --git a/src/View/layoutPublic.phtml b/src/View/layoutPublic.phtml new file mode 100644 index 00000000..ec13100b --- /dev/null +++ b/src/View/layoutPublic.phtml @@ -0,0 +1,43 @@ + + + + <?= $title; ?><?= (!empty($subtitle) ? ' - ' . $subtitle : ''); ?> + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + + diff --git a/src/View/Session.phtml b/src/View/layoutSession.phtml similarity index 100% rename from src/View/Session.phtml rename to src/View/layoutSession.phtml diff --git a/src/WebController.php b/src/WebController.php new file mode 100644 index 00000000..0ac2b8da --- /dev/null +++ b/src/WebController.php @@ -0,0 +1,152 @@ +className = substr(array_pop($class), 0, -10); + } + + public function init() + { + if (!empty($this->layoutName)) { + $this->layout = new View($this->layoutName); + + $this->layout->title = 'PHP Censor'; + $this->layout->breadcrumb = []; + $this->layout->version = trim(file_get_contents(ROOT_DIR . 'VERSION.md')); + + $groups = []; + $groupStore = Factory::getStore('ProjectGroup'); + $groupList = $groupStore->getWhere([], 100, 0, ['title' => 'ASC']); + + foreach ($groupList['items'] as $group) { + $thisGroup = ['title' => $group->getTitle()]; + $projects = Factory::getStore('Project')->getByGroupId($group->getId(), false); + $thisGroup['projects'] = $projects['items']; + $groups[] = $thisGroup; + } + + $archivedProjects = Factory::getStore('Project')->getAll(true); + $this->layout->archived_projects = $archivedProjects['items']; + $this->layout->groups = $groups; + } + } + + /** + * Handle the incoming request. + * + * @param string $action + * @param array $actionParams + * + * @return Response + */ + public function handleAction($action, $actionParams) + { + if (View::exists($this->className . '/' . $action)) { + $this->view = new View($this->className . '/' . $action); + } + + $result = parent::handleAction($action, $actionParams); + + if ($result instanceof Response) { + return $result; + } + + $content = ''; + if (is_string($result)) { + $content = $result; + } elseif ($this->view) { + $content = $this->view->render(); + } + + $response = new Response(); + if ($this->layout) { + $this->layout->content = $content; + + $response->setContent($this->layout->render()); + } else { + $response->setContent($content); + } + + return $response; + } + + /** + * Require that the currently logged in user is an administrator. + * + * @throws ForbiddenException + */ + protected function requireAdmin() + { + if (!$this->currentUserIsAdmin()) { + throw new ForbiddenException('You do not have permission to do that.'); + } + } + + /** + * Check if the currently logged in user is an administrator. + * + * @return boolean + */ + protected function currentUserIsAdmin() + { + $user = $this->getUser(); + if (!$user) { + return false; + } + + return $this->getUser()->getIsAdmin(); + } + + /** + * @return User|null + */ + protected function getUser() + { + if (empty($_SESSION['php-censor-user-id'])) { + return null; + } + + /** @var UserStore $userStore */ + $userStore = Factory::getStore('User'); + + return $userStore->getById($_SESSION['php-censor-user-id']); + } +}