diff --git a/src/Application.php b/src/Application.php index f726ec38..24710b84 100644 --- a/src/Application.php +++ b/src/Application.php @@ -57,9 +57,7 @@ class Application $this->router = new Router($this, $this->request, $this->config); - if (method_exists($this, 'init')) { - $this->init(); - } + $this->init(); } /** 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/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/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); ?> -
getBranch()); ?>
++ = Lang::get('branch_x', $build->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;