From cdc926c62ac6e5141edcfac5f813ff8e413bea5a Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 17 Mar 2018 09:23:49 +0700 Subject: [PATCH 1/3] Refactored View. --- src/View.php | 87 +++++++++++++++++++++++++++++------------- tests/src/ViewTest.php | 7 ---- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/View.php b/src/View.php index 1948b80d..9fecac92 100644 --- a/src/View.php +++ b/src/View.php @@ -8,24 +8,40 @@ use PHPCensor\Store\UserStore; class View { - protected $vars = []; - protected $isContent = false; + /** + * @var array + */ + protected $data = []; + /** + * @var string + */ + protected $viewFile; + + /** + * @var string + */ protected static $extension = 'phtml'; + /** + * @param string $file + * @param string|null $path + */ public function __construct($file, $path = null) { - if ('{@content}' === $file) { - $this->isContent = true; - } else { - if (!self::exists($file, $path)) { - throw new \RuntimeException('View file does not exist: ' . $file); - } - - $this->viewFile = self::getViewFile($file, $path); + if (!self::exists($file, $path)) { + throw new \RuntimeException('View file does not exist: ' . $file); } + + $this->viewFile = self::getViewFile($file, $path); } + /** + * @param string $file + * @param string|null $path + * + * @return string + */ protected static function getViewFile($file, $path = null) { $viewPath = is_null($path) ? (SRC_DIR . 'View/') : $path; @@ -34,6 +50,12 @@ class View return $fullPath; } + /** + * @param string $file + * @param string|null $path + * + * @return boolean + */ public static function exists($file, $path = null) { if (!file_exists(self::getViewFile($file, $path))) { @@ -43,37 +65,50 @@ class View return true; } - public function __isset($var) + /** + * @param string $key + * + * @return boolean + */ + public function __isset($key) { - return isset($this->vars[$var]); + return isset($this->data[$key]); } - public function __get($var) + /** + * @param string $key + * + * @return mixed + */ + public function __get($key) { - return $this->vars[$var]; + return $this->data[$key]; } - public function __set($var, $val) + /** + * @param string $key + * @param mixed $value + */ + public function __set($key, $value) { - $this->vars[$var] = $val; + $this->data[$key] = $value; } + /** + * @return string + */ public function render() { - if ($this->isContent) { - return $this->vars['content']; - } else { - extract($this->vars); + extract($this->data); - ob_start(); + ob_start(); - require($this->viewFile); + require($this->viewFile); - $html = ob_get_contents(); - ob_end_clean(); + $html = ob_get_contents(); + ob_end_clean(); - return $html; - } + return $html; } /** diff --git a/tests/src/ViewTest.php b/tests/src/ViewTest.php index 161534e4..d6a62f5e 100755 --- a/tests/src/ViewTest.php +++ b/tests/src/ViewTest.php @@ -29,11 +29,4 @@ class ViewTest extends \PHPUnit\Framework\TestCase self::assertFalse(isset($view->what)); self::assertTrue($view->render() == 'Hello World'); } - - public function testUserViewVars() - { - $view = new View('{@content}'); - $view->content = 'World'; - self::assertTrue($view->render() == 'World'); - } } From 2a3adf25af550a9d32f03f6b863b8f2aea6242e6 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 17 Mar 2018 09:24:30 +0700 Subject: [PATCH 2/3] Refactored ValidationException (-> InvalidArgumentException). --- src/Command/CreateAdminCommand.php | 3 ++- src/Command/CreateBuildCommand.php | 3 ++- src/Command/InstallCommand.php | 3 ++- .../HttpException/ValidationException.php | 18 ----------------- src/Exception/InvalidArgumentException.php | 7 +++++++ src/Http/Router.php | 10 ++++++---- src/Model.php | 20 +++++++++---------- src/Model/Base/Build.php | 10 +++++----- src/Model/Base/Project.php | 6 +++--- src/Plugin/Util/Factory.php | 15 +++++++------- src/Store.php | 16 +++++++-------- tests/src/Command/CreateBuildCommandTest.php | 3 ++- tests/src/HttpExceptionTest.php | 10 ---------- tests/src/Model/Base/BuildTest.php | 4 ++-- tests/src/Model/Base/ProjectTest.php | 2 +- tests/src/Model/BuildTest.php | 10 +++++----- tests/src/Model/ProjectTest.php | 4 ++-- tests/src/Plugin/Util/FactoryTest.php | 12 +++++------ tests/src/StoreMysqlTest.php | 7 ++++--- tests/src/StorePostgresqlTest.php | 7 ++++--- 20 files changed, 79 insertions(+), 91 deletions(-) delete mode 100644 src/Exception/HttpException/ValidationException.php create mode 100644 src/Exception/InvalidArgumentException.php diff --git a/src/Command/CreateAdminCommand.php b/src/Command/CreateAdminCommand.php index 34335573..ae767ef2 100644 --- a/src/Command/CreateAdminCommand.php +++ b/src/Command/CreateAdminCommand.php @@ -2,6 +2,7 @@ namespace PHPCensor\Command; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Service\UserService; use PHPCensor\Store\UserStore; use Symfony\Component\Console\Command\Command; @@ -58,7 +59,7 @@ class CreateAdminCommand extends Command // Function to validate email address. $mailValidator = function ($answer) { if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) { - throw new \InvalidArgumentException('Must be a valid email address.'); + throw new InvalidArgumentException('Must be a valid email address.'); } return $answer; diff --git a/src/Command/CreateBuildCommand.php b/src/Command/CreateBuildCommand.php index 237d85b3..14004134 100644 --- a/src/Command/CreateBuildCommand.php +++ b/src/Command/CreateBuildCommand.php @@ -2,6 +2,7 @@ namespace PHPCensor\Command; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Model\Build; use PHPCensor\Service\BuildService; use PHPCensor\Store\ProjectStore; @@ -71,7 +72,7 @@ class CreateBuildCommand extends Command $project = $this->projectStore->getById($projectId); if (empty($project) || $project->getArchived()) { - throw new \InvalidArgumentException('Project does not exist: ' . $projectId); + throw new InvalidArgumentException('Project does not exist: ' . $projectId); } try { diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index dba9396b..326a383f 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -6,6 +6,7 @@ use Exception; use PDO; use PHPCensor\Config; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Store\Factory; use PHPCensor\Model\ProjectGroup; use PHPCensor\Store\UserStore; @@ -185,7 +186,7 @@ class InstallCommand extends Command // Function to validate email address. $mailValidator = function ($answer) { if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) { - throw new \InvalidArgumentException('Must be a valid email address.'); + throw new InvalidArgumentException('Must be a valid email address.'); } return $answer; diff --git a/src/Exception/HttpException/ValidationException.php b/src/Exception/HttpException/ValidationException.php deleted file mode 100644 index 3bdda75c..00000000 --- a/src/Exception/HttpException/ValidationException.php +++ /dev/null @@ -1,18 +0,0 @@ -routes, ['route' => $route, 'callback' => $callback, 'defaults' => $options]); diff --git a/src/Model.php b/src/Model.php index 292610eb..6fe8dfe3 100644 --- a/src/Model.php +++ b/src/Model.php @@ -2,7 +2,7 @@ namespace PHPCensor; -use PHPCensor\Exception\HttpException\ValidationException; +use PHPCensor\Exception\InvalidArgumentException; class Model { @@ -29,7 +29,7 @@ class Model if (is_array($initialData)) { foreach ($initialData as $index => $item) { if (!array_key_exists($index, $this->data)) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Model "%s" doesn\'t have field "%s"', get_called_class(), $index @@ -81,12 +81,12 @@ class Model * @param string $name * @param mixed $value * - * @throws ValidationException + * @throws InvalidArgumentException */ protected function validateString($name, $value) { if (!is_string($value) && !is_null($value)) { - throw new ValidationException('Column "' . $name . '" must be a string.'); + throw new InvalidArgumentException('Column "' . $name . '" must be a string.'); } } @@ -94,12 +94,12 @@ class Model * @param string $name * @param mixed $value * - * @throws ValidationException + * @throws InvalidArgumentException */ protected function validateInt($name, $value) { if (!is_integer($value) && !is_null($value)) { - throw new ValidationException('Column "' . $name . '" must be an integer.'); + throw new InvalidArgumentException('Column "' . $name . '" must be an integer.'); } } @@ -107,12 +107,12 @@ class Model * @param string $name * @param mixed $value * - * @throws ValidationException + * @throws InvalidArgumentException */ protected function validateBoolean($name, $value) { if (!is_bool($value) && !is_null($value)) { - throw new ValidationException('Column "' . $name . '" must be a boolean.'); + throw new InvalidArgumentException('Column "' . $name . '" must be a boolean.'); } } @@ -120,12 +120,12 @@ class Model * @param string $name * @param mixed $value * - * @throws ValidationException + * @throws InvalidArgumentException */ protected function validateNotNull($name, $value) { if (is_null($value)) { - throw new ValidationException('Column "' . $name . '" must not be null.'); + throw new InvalidArgumentException('Column "' . $name . '" must not be null.'); } } } diff --git a/src/Model/Base/Build.php b/src/Model/Base/Build.php index c356aa2b..908a3adf 100644 --- a/src/Model/Base/Build.php +++ b/src/Model/Base/Build.php @@ -2,7 +2,7 @@ namespace PHPCensor\Model\Base; -use PHPCensor\Exception\HttpException\ValidationException; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Model; class Build extends Model @@ -155,7 +155,7 @@ class Build extends Model /** * @param integer $value * - * @throws ValidationException + * @throws InvalidArgumentException * * @return boolean */ @@ -165,7 +165,7 @@ class Build extends Model $this->validateInt('status', $value); if (!in_array($value, $this->allowedStatuses, true)) { - throw new ValidationException( + throw new InvalidArgumentException( 'Column "status" must be one of: ' . join(', ', $this->allowedStatuses) . '.' ); } @@ -474,7 +474,7 @@ class Build extends Model /** * @param integer $value * - * @throws ValidationException + * @throws InvalidArgumentException * * @return boolean */ @@ -483,7 +483,7 @@ class Build extends Model $this->validateInt('source', $value); if (!in_array($value, $this->allowedSources, true)) { - throw new ValidationException( + throw new InvalidArgumentException( 'Column "source" must be one of: ' . join(', ', $this->allowedSources) . '.' ); } diff --git a/src/Model/Base/Project.php b/src/Model/Base/Project.php index 15e0c250..82565f14 100644 --- a/src/Model/Base/Project.php +++ b/src/Model/Base/Project.php @@ -2,7 +2,7 @@ namespace PHPCensor\Model\Base; -use PHPCensor\Exception\HttpException\ValidationException; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Model; class Project extends Model @@ -274,7 +274,7 @@ class Project extends Model * * @return boolean * - * @throws ValidationException + * @throws InvalidArgumentException */ public function setType($value) { @@ -282,7 +282,7 @@ class Project extends Model $this->validateString('type', $value); if (!in_array($value, $this->allowedTypes, true)) { - throw new ValidationException( + throw new InvalidArgumentException( 'Column "type" must be one of: ' . join(', ', $this->allowedTypes) . '.' ); } diff --git a/src/Plugin/Util/Factory.php b/src/Plugin/Util/Factory.php index ea55b1f8..4dd2ae2f 100644 --- a/src/Plugin/Util/Factory.php +++ b/src/Plugin/Util/Factory.php @@ -2,6 +2,7 @@ namespace PHPCensor\Plugin\Util; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Plugin; use Pimple\Container; @@ -68,11 +69,9 @@ class Factory * Builds an instance of plugin of class $className. $options will * be passed along with any resources registered with the factory. * - * @param $className + * @param string $className * @param array|null $options * - * @throws \InvalidArgumentException if $className doesn't represent a valid plugin - * * @return \PHPCensor\Plugin */ public function buildPlugin($className, $options = []) @@ -103,10 +102,12 @@ class Factory } /** - * @param callable $loader + * @param callable $loader * @param string|null $name * @param string|null $type - * @throws \InvalidArgumentException + * + * @throws InvalidArgumentException + * * @internal param mixed $resource */ public function registerResource( @@ -115,13 +116,13 @@ class Factory $type = null ) { if ($name === null && $type === null) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( "Type or Name must be specified" ); } if (!($loader instanceof \Closure)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( '$loader is expected to be a function' ); } diff --git a/src/Store.php b/src/Store.php index ce218f92..89a90087 100644 --- a/src/Store.php +++ b/src/Store.php @@ -2,6 +2,8 @@ namespace PHPCensor; +use PHPCensor\Exception\InvalidArgumentException; + abstract class Store { /** @@ -110,15 +112,14 @@ abstract class Store * @param Model $obj * @param boolean $saveAllColumns * - * @throws \RuntimeException - * @throws \InvalidArgumentException + * @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.'); + throw new InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.'); } $data = $obj->getDataArray(); @@ -207,15 +208,14 @@ abstract class Store /** * @param Model $obj * - * @throws \RuntimeException - * @throws \InvalidArgumentException + * @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.'); + throw new InvalidArgumentException(get_class($obj) . ' is an invalid model type for this store.'); } $data = $obj->getDataArray(); @@ -230,14 +230,14 @@ abstract class Store /** * @param string $field * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return string */ protected function fieldCheck($field) { if (empty($field)) { - throw new \InvalidArgumentException('You cannot have an empty field name.'); + throw new InvalidArgumentException('You cannot have an empty field name.'); } if (strpos($field, '.') === false) { diff --git a/tests/src/Command/CreateBuildCommandTest.php b/tests/src/Command/CreateBuildCommandTest.php index 06cb7bd1..ff08008d 100644 --- a/tests/src/Command/CreateBuildCommandTest.php +++ b/tests/src/Command/CreateBuildCommandTest.php @@ -3,6 +3,7 @@ namespace Tests\PHPCensor\Command; use PHPCensor\Command\CreateBuildCommand; +use PHPCensor\Exception\InvalidArgumentException; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -68,7 +69,7 @@ class CreateBuildCommandTest extends \PHPUnit\Framework\TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException InvalidArgumentException */ public function testExecuteWithUnknownProjectId() { diff --git a/tests/src/HttpExceptionTest.php b/tests/src/HttpExceptionTest.php index b328870a..53865e48 100755 --- a/tests/src/HttpExceptionTest.php +++ b/tests/src/HttpExceptionTest.php @@ -73,14 +73,4 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase self::assertTrue($ex->getStatusMessage() == 'Internal Server Error'); } } - - public function testValidationException() - { - try { - throw new HttpException\ValidationException('Test'); - } catch (HttpException $ex) { - self::assertTrue($ex->getErrorCode() == 400); - self::assertTrue($ex->getStatusMessage() == 'Bad Request'); - } - } } diff --git a/tests/src/Model/Base/BuildTest.php b/tests/src/Model/Base/BuildTest.php index db000c94..23b6e104 100644 --- a/tests/src/Model/Base/BuildTest.php +++ b/tests/src/Model/Base/BuildTest.php @@ -81,7 +81,7 @@ class BuildTest extends TestCase $result = $build->setStatus(Build::STATUS_FAILED); self::assertEquals(false, $result); - self::expectException('\PHPCensor\Exception\HttpException\ValidationException'); + self::expectException('\PHPCensor\Exception\InvalidArgumentException'); $build->setStatus(10); } @@ -230,7 +230,7 @@ class BuildTest extends TestCase $result = $build->setSource(Build::SOURCE_WEBHOOK_PULL_REQUEST); self::assertEquals(false, $result); - self::expectException('\PHPCensor\Exception\HttpException\ValidationException'); + self::expectException('\PHPCensor\Exception\InvalidArgumentException'); $build->setSource(20); } diff --git a/tests/src/Model/Base/ProjectTest.php b/tests/src/Model/Base/ProjectTest.php index de1ebc9b..3792c966 100644 --- a/tests/src/Model/Base/ProjectTest.php +++ b/tests/src/Model/Base/ProjectTest.php @@ -138,7 +138,7 @@ class ProjectTest extends TestCase $result = $project->setType('git'); self::assertEquals(false, $result); - self::expectException('\PHPCensor\Exception\HttpException\ValidationException'); + self::expectException('\PHPCensor\Exception\InvalidArgumentException'); $project->setType('invalid-type'); } diff --git a/tests/src/Model/BuildTest.php b/tests/src/Model/BuildTest.php index e34c2c31..56360d81 100644 --- a/tests/src/Model/BuildTest.php +++ b/tests/src/Model/BuildTest.php @@ -2,7 +2,7 @@ namespace Tests\PHPCensor\Model; -use PHPCensor\Exception\HttpException\ValidationException; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Model\Build; /** @@ -49,7 +49,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase 'branch' => 'dev', 'unknown' => 'unknown', ]); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'Model "PHPCensor\Model\Build" doesn\'t have field "unknown"', $e->getMessage() @@ -65,7 +65,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase try { $build->setLog([]); - } catch (ValidationException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'Column "log" must be a string.', $e->getMessage() @@ -77,7 +77,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase try { $build->setSource('5'); - } catch (ValidationException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'Column "source" must be an integer.', $e->getMessage() @@ -86,7 +86,7 @@ class BuildTest extends \PHPUnit\Framework\TestCase try { $build->setId(null); - } catch (ValidationException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'Column "id" must not be null.', $e->getMessage() diff --git a/tests/src/Model/ProjectTest.php b/tests/src/Model/ProjectTest.php index ef9eda58..419e43c1 100644 --- a/tests/src/Model/ProjectTest.php +++ b/tests/src/Model/ProjectTest.php @@ -2,7 +2,7 @@ namespace Tests\PHPCensor\Model; -use PHPCensor\Exception\HttpException\ValidationException; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Model\Project; use PHPCensor\Model; @@ -20,7 +20,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase try { $project->setArchived('true'); - } catch (ValidationException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'Column "archived" must be a boolean.', $e->getMessage() diff --git a/tests/src/Plugin/Util/FactoryTest.php b/tests/src/Plugin/Util/FactoryTest.php index b760b24a..e8e7f1c2 100644 --- a/tests/src/Plugin/Util/FactoryTest.php +++ b/tests/src/Plugin/Util/FactoryTest.php @@ -34,13 +34,15 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { public function testRegisterResourceThrowsExceptionWithoutTypeAndName() { - $this->setExpectedException('InvalidArgumentException', 'Type or Name must be specified'); + self::expectException('\PHPCensor\Exception\InvalidArgumentException'); + self::expectExceptionMessage('Type or Name must be specified'); $this->testedFactory->registerResource($this->resourceLoader, null, null); } public function testRegisterResourceThrowsExceptionIfLoaderIsntFunction() { - $this->setExpectedException('InvalidArgumentException', '$loader is expected to be a function'); + self::expectException('\PHPCensor\Exception\InvalidArgumentException'); + self::expectExceptionMessage('$loader is expected to be a function'); $this->testedFactory->registerResource(["dummy"], "TestName", "TestClass"); } @@ -53,10 +55,8 @@ class FactoryTest extends \PHPUnit\Framework\TestCase { public function testBuildPluginThrowsExceptionIfMissingResourcesForRequiredArg() { - $this->setExpectedException( - 'DomainException', - 'Unsatisfied dependency: requiredArgument' - ); + self::expectException('\DomainException'); + self::expectExceptionMessage('Unsatisfied dependency: requiredArgument'); $pluginClass = $this->getFakePluginClassName('ExamplePluginWithSingleRequiredArg'); $plugin = $this->testedFactory->buildPlugin($pluginClass); diff --git a/tests/src/StoreMysqlTest.php b/tests/src/StoreMysqlTest.php index 0bd3981f..80693b37 100755 --- a/tests/src/StoreMysqlTest.php +++ b/tests/src/StoreMysqlTest.php @@ -4,6 +4,7 @@ namespace Tests\PHPCensor; use PHPCensor\Config; use PHPCensor\Database; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; use PHPCensor\Model\ProjectGroup; @@ -177,7 +178,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase try { $data = $testStore->getWhere(['' => 0], 100, 0, ['id' => 'ASC']); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals('You cannot have an empty field name.', $e->getMessage()); } @@ -233,7 +234,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase $model->setId(1); $testStore->save($model); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'PHPCensor\Model\Project is an invalid model type for this store.', $e->getMessage() @@ -258,7 +259,7 @@ class StoreMysqlTest extends \PHPUnit_Extensions_Database_TestCase $model->setId(1); $testStore->delete($model); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'PHPCensor\Model\Project is an invalid model type for this store.', $e->getMessage() diff --git a/tests/src/StorePostgresqlTest.php b/tests/src/StorePostgresqlTest.php index 5f3bef70..1c6e17cd 100755 --- a/tests/src/StorePostgresqlTest.php +++ b/tests/src/StorePostgresqlTest.php @@ -4,6 +4,7 @@ namespace Tests\PHPCensor; use PHPCensor\Config; use PHPCensor\Database; +use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Store\Factory; use PHPCensor\Model\Project; use PHPCensor\Model\ProjectGroup; @@ -164,7 +165,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase try { $data = $testStore->getWhere(['' => 0], 100, 0, ['id' => 'ASC']); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals('You cannot have an empty field name.', $e->getMessage()); } @@ -228,7 +229,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase $model->setId(1); $testStore->save($model); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'PHPCensor\Model\Project is an invalid model type for this store.', $e->getMessage() @@ -253,7 +254,7 @@ class StorePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase $model->setId(1); $testStore->delete($model); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { self::assertEquals( 'PHPCensor\Model\Project is an invalid model type for this store.', $e->getMessage() From 8a29f5aefecc73f7f9f9e8aab9657f3903df660c Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 17 Mar 2018 10:58:23 +0700 Subject: [PATCH 3/3] Code style fixes (' 'router = new Router($this, $this->request, $this->config); - if (method_exists($this, 'init')) { - $this->init(); - } + $this->init(); } /** diff --git a/src/Helper/Lang.php b/src/Helper/Lang.php index 57964d85..48c56148 100644 --- a/src/Helper/Lang.php +++ b/src/Helper/Lang.php @@ -54,16 +54,6 @@ class Lang return $string; } - /** - * Output a specific string from the language file. - * - * @param array ...$params - */ - public static function out(...$params) - { - print call_user_func_array(['PHPCensor\Helper\Lang', 'get'], $params); - } - /** * Get the currently active language. * diff --git a/src/View/Build/errors.phtml b/src/View/Build/errors.phtml index 09b068a2..c7b87be6 100644 --- a/src/View/Build/errors.phtml +++ b/src/View/Build/errors.phtml @@ -1,9 +1,16 @@ getFileLinkTemplate(); -/** @var \PHPCensor\Model\BuildError[] $errors */ foreach ($errors as $error): $link = str_replace('{BASEFILE}', basename($error->getFile()), $linkTemplate); @@ -11,7 +18,6 @@ foreach ($errors as $error): $link = str_replace('{LINE}', $error->getLineStart(), $link); $link = str_replace('{LINE_END}', $error->getLineEnd(), $link); ?> - getIsNew()): ?> @@ -37,7 +43,5 @@ foreach ($errors as $error): getMessage())); ?> - - diff --git a/src/View/Build/header-row.phtml b/src/View/Build/header-row.phtml index 126f39bf..8b47dfeb 100644 --- a/src/View/Build/header-row.phtml +++ b/src/View/Build/header-row.phtml @@ -19,12 +19,18 @@ use PHPCensor\Model\Build;

getProject()->getTitle(); ?> - getStatus() == \PHPCensor\Model\Build::STATUS_PENDING): ?> - getCreateDate()->format('H:i')); ?> - getStatus() == \PHPCensor\Model\Build::STATUS_RUNNING): ?> - getStartDate()->format('H:i')); ?> + getStatus() == Build::STATUS_PENDING): ?> + + getCreateDate()->format('H:i')); ?> + + getStatus() == Build::STATUS_RUNNING): ?> + + getStartDate()->format('H:i')); ?> +

-

getBranch()); ?>

+

+ getBranch()); ?> +

diff --git a/src/View/Build/view.phtml b/src/View/Build/view.phtml index 888323e7..ed235b42 100644 --- a/src/View/Build/view.phtml +++ b/src/View/Build/view.phtml @@ -15,14 +15,14 @@ use PHPCensor\Model\BuildError;

- +

- + - + - + - +
@@ -32,7 +32,7 @@ use PHPCensor\Model\BuildError;
getSource()): ?> @@ -53,7 +53,7 @@ use PHPCensor\Model\BuildError;
getEnvironment(); @@ -63,7 +63,7 @@ use PHPCensor\Model\BuildError;
getBranch(); ?> @@ -89,20 +89,20 @@ use PHPCensor\Model\BuildError;

- +

- + - + - + - + @@ -132,35 +132,35 @@ use PHPCensor\Model\BuildError;

- +

- getSourceHumanize()); ?> + getSourceHumanize()); ?>
getCommitId(), 0, 7); ?> @@ -111,14 +111,14 @@ use PHPCensor\Model\BuildError;
getCommitterEmail(); ?>
getCommitMessage()); ?>
- + - + - + - + @@ -289,12 +289,12 @@ use PHPCensor\Model\BuildError;
getCreateDate() ? $build->getCreateDate()->format('Y-m-d H:i:s') : ''); ?>
getStartDate() ? $build->getStartDate()->format('Y-m-d H:i:s') : ''); ?>
getFinishDate() ? $build->getFinishDate()->format('Y-m-d H:i:s') : ''); ?>
getDuration(); ?>
- - - - - - + + + + + + diff --git a/src/View/Group/edit.phtml b/src/View/Group/edit.phtml index 389e6f8c..1eae6177 100644 --- a/src/View/Group/edit.phtml +++ b/src/View/Group/edit.phtml @@ -5,7 +5,7 @@ use PHPCensor\Helper\Lang; ?>
-

+

diff --git a/src/View/Group/index.phtml b/src/View/Group/index.phtml index b6008e48..d63b6638 100644 --- a/src/View/Group/index.phtml +++ b/src/View/Group/index.phtml @@ -5,7 +5,7 @@ use PHPCensor\Helper\Lang; ?> @@ -13,8 +13,8 @@ use PHPCensor\Helper\Lang;
- - + + @@ -25,13 +25,13 @@ use PHPCensor\Helper\Lang; - + @@ -52,7 +52,7 @@ $branches = $build->getExtra('branches'); - +
- + getUser()->getIsAdmin() && (!count($group['projects']))): ?>
diff --git a/src/View/Project/ajax-builds.phtml b/src/View/Project/ajax-builds.phtml index 1ed869fc..e62b3be6 100644 --- a/src/View/Project/ajax-builds.phtml +++ b/src/View/Project/ajax-builds.phtml @@ -11,7 +11,7 @@ use PHPCensor\Model\Build;
#getId(), 6, '0', STR_PAD_LEFT); ?> getCreateDate()->format('Y-m-d H:i:s'); ?>getSourceHumanize()); ?>getSourceHumanize()); ?>
- + getUser()->getIsAdmin()): ?>
diff --git a/src/View/Project/edit.phtml b/src/View/Project/edit.phtml index 4148d438..2de6bd46 100644 --- a/src/View/Project/edit.phtml +++ b/src/View/Project/edit.phtml @@ -24,7 +24,7 @@
-

+

@@ -37,7 +37,7 @@
-

+

diff --git a/src/View/Project/view.phtml b/src/View/Project/view.phtml index 7fbf3583..dd7b4f34 100644 --- a/src/View/Project/view.phtml +++ b/src/View/Project/view.phtml @@ -17,11 +17,11 @@ use PHPCensor\Helper\Lang;
- + - + getUser()->getIsAdmin()): ?> - + - + - + - + - + - + @@ -63,16 +63,16 @@ use PHPCensor\Helper\Lang;