From 7f01a46e692840f744df26b016a84763121d308a Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Fri, 15 Jul 2022 12:48:41 +0300 Subject: [PATCH 01/17] Start migration to PHP 8.0 --- composer.json | 2 +- src/Common/Container/JsonSerialize.php | 2 +- src/Config/Config.php | 2 +- src/Config/ConfigLoader.php | 6 +++--- src/Controller/Controller.php | 2 +- src/Response/ResponseTrait.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 2bf5b11d..ca6daa82 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Lightweight PHP framework", "type": "library", "require": { - "php": ">=7.4", + "php": ">=8.0", "ext-PDO": "*", "ext-pdo_mysql": "*", "ext-json": "*", diff --git a/src/Common/Container/JsonSerialize.php b/src/Common/Container/JsonSerialize.php index 84ffcee1..656dae15 100644 --- a/src/Common/Container/JsonSerialize.php +++ b/src/Common/Container/JsonSerialize.php @@ -25,7 +25,7 @@ trait JsonSerialize * * @return array */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return $this->toArray(); } diff --git a/src/Config/Config.php b/src/Config/Config.php index 2531824c..fe886d4a 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -35,7 +35,7 @@ class Config * @return array|mixed * @throws ConfigException */ - public function get(...$keys) + public function get(...$keys): mixed { // configuration is missed if (empty($this->container)) { diff --git a/src/Config/ConfigLoader.php b/src/Config/ConfigLoader.php index af16bf0c..c376c2cb 100644 --- a/src/Config/ConfigLoader.php +++ b/src/Config/ConfigLoader.php @@ -26,17 +26,17 @@ class ConfigLoader /** * @var array configuration data */ - protected $config; + protected array $config; /** * @var string path to configuration files */ - protected $path; + protected string $path; /** * @var string environment */ - protected $environment; + protected string $environment; /** * @return array diff --git a/src/Controller/Controller.php b/src/Controller/Controller.php index 38d303d8..774265fc 100644 --- a/src/Controller/Controller.php +++ b/src/Controller/Controller.php @@ -396,7 +396,7 @@ private function saveData(): bool * * @return Data */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return $this->getData(); } diff --git a/src/Response/ResponseTrait.php b/src/Response/ResponseTrait.php index a7204f27..4f196f95 100644 --- a/src/Response/ResponseTrait.php +++ b/src/Response/ResponseTrait.php @@ -22,7 +22,7 @@ trait ResponseTrait /** * @return string */ - abstract public function jsonSerialize(); + abstract public function jsonSerialize(): mixed; /** * @return string From bf8bb75eebe01f261bf4d15d7462990968399b34 Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Fri, 15 Jul 2022 17:24:15 +0300 Subject: [PATCH 02/17] Start migration to PHP 8.0 --- src/Application/Application.php | 8 ++++---- src/Auth/AbstractIdentity.php | 2 +- src/Auth/Auth.php | 4 ++-- src/Auth/IdentityInterface.php | 8 ++++---- src/Common/Container/ArrayAccess.php | 10 +++++----- src/Common/Container/Container.php | 6 +++--- src/Common/Container/MagicAccess.php | 4 ++-- src/Common/Container/RegularAccess.php | 18 +++++++++--------- src/Common/Helper.php | 4 ++-- src/Common/Options.php | 6 +++--- src/Config/Config.php | 8 ++++---- src/Controller/Controller.php | 2 +- src/Db/Db.php | 8 ++++---- src/Db/Relations.php | 4 ++-- tests/src/Fixtures/Models/UserAdmin.php | 2 +- tests/src/Fixtures/Models/UserGuest.php | 2 +- 16 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 07e53358..1efda518 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -58,22 +58,22 @@ class Application /** * @var string Environment name */ - protected $environment = 'production'; + protected string $environment = 'production'; /** * @var string Application path */ - protected $path; + protected string $path; /** * @var bool Debug application flag */ - protected $debugFlag = false; + protected bool $debugFlag = false; /** * @var bool Layout usage flag */ - protected $layoutFlag = true; + protected bool $layoutFlag = true; /** * Get application environment diff --git a/src/Auth/AbstractIdentity.php b/src/Auth/AbstractIdentity.php index 9397fd5f..da5dd924 100644 --- a/src/Auth/AbstractIdentity.php +++ b/src/Auth/AbstractIdentity.php @@ -40,7 +40,7 @@ public function getId(): ?int /** * {@inheritdoc} */ - public function hasPrivilege($module, $privilege): bool + public function hasPrivilege(string $module, string $privilege): bool { $privileges = $this->getPrivileges(); diff --git a/src/Auth/Auth.php b/src/Auth/Auth.php index 20bc266d..184f5684 100644 --- a/src/Auth/Auth.php +++ b/src/Auth/Auth.php @@ -27,9 +27,9 @@ class Auth use Options; /** - * @var IdentityInterface Instance of EntityInterface + * @var ?IdentityInterface Instance of EntityInterface */ - protected $identity; + protected ?IdentityInterface $identity; /** * Setup identity diff --git a/src/Auth/IdentityInterface.php b/src/Auth/IdentityInterface.php index 0fb0b574..f7658664 100644 --- a/src/Auth/IdentityInterface.php +++ b/src/Auth/IdentityInterface.php @@ -21,7 +21,7 @@ interface IdentityInterface /** * Get an ID that can uniquely identify a user * - * @return integer + * @return int|null */ public function getId(): ?int; @@ -35,10 +35,10 @@ public function getPrivileges(): array; /** * Has it privilege? * - * @param string $module - * @param string $privilege + * @param string $module + * @param string $privilege * * @return bool */ - public function hasPrivilege($module, $privilege): bool; + public function hasPrivilege(string $module, string $privilege): bool; } diff --git a/src/Common/Container/ArrayAccess.php b/src/Common/Container/ArrayAccess.php index 83cfa058..a10bde89 100644 --- a/src/Common/Container/ArrayAccess.php +++ b/src/Common/Container/ArrayAccess.php @@ -20,7 +20,7 @@ * @author Anton Shevchuk * @see ArrayAccess * - * @method void doSetContainer(string $key, $value) + * @method void doSetContainer(string $key, mixed $value) * @method mixed doGetContainer(string $key) * @method bool doContainsContainer(string $key) * @method void doDeleteContainer(string $key) @@ -35,7 +35,7 @@ trait ArrayAccess * * @throws InvalidArgumentException */ - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { if (null === $offset) { throw new InvalidArgumentException('Class `Common\Container\ArrayAccess` support only associative arrays'); @@ -50,7 +50,7 @@ public function offsetSet($offset, $value): void * * @return mixed */ - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return $this->doGetContainer($offset); } @@ -62,7 +62,7 @@ public function offsetGet($offset) * * @return bool */ - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return $this->doContainsContainer($offset); } @@ -72,7 +72,7 @@ public function offsetExists($offset): bool * * @param mixed $offset */ - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { $this->doDeleteContainer($offset); } diff --git a/src/Common/Container/Container.php b/src/Common/Container/Container.php index 880805bc..b9b8844e 100644 --- a/src/Common/Container/Container.php +++ b/src/Common/Container/Container.php @@ -23,7 +23,7 @@ trait Container /** * @var array Container of elements */ - protected $container = []; + protected array $container = []; /** * Set key/value pair @@ -33,7 +33,7 @@ trait Container * * @return void */ - protected function doSetContainer(string $key, $value): void + protected function doSetContainer(string $key, mixed $value): void { $this->container[$key] = $value; } @@ -45,7 +45,7 @@ protected function doSetContainer(string $key, $value): void * * @return mixed */ - protected function doGetContainer(string $key) + protected function doGetContainer(string $key): mixed { if ($this->doContainsContainer($key)) { return $this->container[$key]; diff --git a/src/Common/Container/MagicAccess.php b/src/Common/Container/MagicAccess.php index 8245ac5d..172a9cfa 100644 --- a/src/Common/Container/MagicAccess.php +++ b/src/Common/Container/MagicAccess.php @@ -17,7 +17,7 @@ * @package Bluz\Common * @author Anton Shevchuk * - * @method void doSetContainer(string $key, $value) + * @method void doSetContainer(string $key, mixed $value) * @method mixed doGetContainer(string $key) * @method bool doContainsContainer(string $key) * @method void doDeleteContainer(string $key) @@ -32,7 +32,7 @@ trait MagicAccess * * @return void */ - public function __set(string $key, $value): void + public function __set(string $key, mixed $value): void { $this->doSetContainer($key, $value); } diff --git a/src/Common/Container/RegularAccess.php b/src/Common/Container/RegularAccess.php index 74af75f3..d6b56b40 100644 --- a/src/Common/Container/RegularAccess.php +++ b/src/Common/Container/RegularAccess.php @@ -17,7 +17,7 @@ * @package Bluz\Common * @author Anton Shevchuk * - * @method void doSetContainer(string $key, $value) + * @method void doSetContainer(string $key, mixed $value) * @method mixed doGetContainer(string $key) * @method bool doContainsContainer(string $key) * @method void doDeleteContainer(string $key) @@ -27,12 +27,12 @@ trait RegularAccess /** * Set key/value pair * - * @param string $key + * @param string $key * @param mixed $value * * @return void */ - public function set($key, $value): void + public function set(string $key, mixed $value): void { $this->doSetContainer($key, $value); } @@ -40,11 +40,11 @@ public function set($key, $value): void /** * Get value by key * - * @param string $key + * @param string $key * * @return mixed */ - public function get($key) + public function get(string $key): mixed { return $this->doGetContainer($key); } @@ -52,11 +52,11 @@ public function get($key) /** * Check contains key in container * - * @param string $key + * @param string $key * * @return bool */ - public function contains($key): bool + public function contains(string $key): bool { return $this->doContainsContainer($key); } @@ -64,11 +64,11 @@ public function contains($key): bool /** * Delete value by key * - * @param string $key + * @param string $key * * @return void */ - public function delete($key): void + public function delete(string $key): void { $this->doDeleteContainer($key); } diff --git a/src/Common/Helper.php b/src/Common/Helper.php index a9dcc444..cf1ff906 100644 --- a/src/Common/Helper.php +++ b/src/Common/Helper.php @@ -26,12 +26,12 @@ trait Helper /** * @var array[] list of helpers */ - protected static $helpers = []; + protected static array $helpers = []; /** * @var array[] list of helpers paths */ - protected static $helpersPath = []; + protected static array $helpersPath = []; /** * Add helper path diff --git a/src/Common/Options.php b/src/Common/Options.php index 1db0d85b..c2ca1a23 100644 --- a/src/Common/Options.php +++ b/src/Common/Options.php @@ -47,7 +47,7 @@ trait Options /** * @var array options store */ - protected $options = []; + protected array $options = []; /** * Get option by key @@ -57,7 +57,7 @@ trait Options * * @return mixed */ - public function getOption(string $key, ...$keys) + public function getOption(string $key, ...$keys): mixed { $method = 'get' . Str::toCamelCase($key); if (method_exists($this, $method)) { @@ -74,7 +74,7 @@ public function getOption(string $key, ...$keys) * * @return void */ - public function setOption(string $key, $value): void + public function setOption(string $key, mixed $value): void { $method = 'set' . Str::toCamelCase($key); if (method_exists($this, $method)) { diff --git a/src/Config/Config.php b/src/Config/Config.php index fe886d4a..508ff0b2 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -30,22 +30,22 @@ class Config /** * Return configuration by key * - * @param array $keys + * @param string|array $key * * @return array|mixed * @throws ConfigException */ - public function get(...$keys): mixed + public function get($key): mixed { // configuration is missed if (empty($this->container)) { throw new ConfigException('System configuration is missing'); } - if (!count($keys)) { + if (!count($key)) { return $this->container; } - return Collection::get($this->container, ...$keys); + return Collection::get($this->container, ...$key); } } diff --git a/src/Controller/Controller.php b/src/Controller/Controller.php index 774265fc..94a1430a 100644 --- a/src/Controller/Controller.php +++ b/src/Controller/Controller.php @@ -56,7 +56,7 @@ class Controller implements JsonSerializable /** * @var string */ - protected $module; + protected $mzodule; /** * @var string diff --git a/src/Db/Db.php b/src/Db/Db.php index daec17bf..6f47b5c3 100644 --- a/src/Db/Db.php +++ b/src/Db/Db.php @@ -37,7 +37,7 @@ class Db * @var array * @link http://php.net/manual/en/pdo.construct.php */ - protected $connect = [ + protected array $connect = [ 'type' => 'mysql', 'host' => 'localhost', 'name' => '', @@ -52,14 +52,14 @@ class Db * @var array * @link http://php.net/manual/en/pdo.setattribute.php */ - protected $attributes = [ + protected array $attributes = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]; /** - * @var PDO PDO instance + * @var ?PDO PDO instance */ - protected $handler; + protected ?PDO $handler; /** * Setup connection diff --git a/src/Db/Relations.php b/src/Db/Relations.php index fc10c1a5..bb711d82 100644 --- a/src/Db/Relations.php +++ b/src/Db/Relations.php @@ -35,7 +35,7 @@ class Relations * * @var array */ - protected static $relations; + protected static array $relations; /** * Class map, i.e. @@ -48,7 +48,7 @@ class Relations * * @var array */ - protected static $modelClassMap; + protected static array $modelClassMap; /** * Setup relation between two models diff --git a/tests/src/Fixtures/Models/UserAdmin.php b/tests/src/Fixtures/Models/UserAdmin.php index 7b70e5ec..60b00643 100644 --- a/tests/src/Fixtures/Models/UserAdmin.php +++ b/tests/src/Fixtures/Models/UserAdmin.php @@ -59,7 +59,7 @@ public function hasRole($roleId) * * @return boolean */ - public function hasPrivilege($module, $privilege): bool + public function hasPrivilege(string $module, string $privilege): bool { return true; } diff --git a/tests/src/Fixtures/Models/UserGuest.php b/tests/src/Fixtures/Models/UserGuest.php index 1f16c39a..33e3c760 100644 --- a/tests/src/Fixtures/Models/UserGuest.php +++ b/tests/src/Fixtures/Models/UserGuest.php @@ -59,7 +59,7 @@ public function hasRole($roleId) * * @return boolean */ - public function hasPrivilege($module, $privilege): bool + public function hasPrivilege(string $module, string $privilege): bool { return false; } From 83e67973c19a5bd899aeb7d9d448939d7b955698 Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Fri, 15 Jul 2022 17:24:36 +0300 Subject: [PATCH 03/17] Start migration to PHP 8.0 --- src/Db/Query/Traits/Where.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Db/Query/Traits/Where.php b/src/Db/Query/Traits/Where.php index c7bb8dad..540b9208 100644 --- a/src/Db/Query/Traits/Where.php +++ b/src/Db/Query/Traits/Where.php @@ -45,7 +45,7 @@ trait Where * ; * * - * @param string[] $conditions optional the query restriction predicates + * @param array $conditions optional the query restriction predicates * * @return $this */ From 92ca97ea32ab010e82718cbdac953d7a909df007 Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Wed, 1 Feb 2023 16:00:29 +0100 Subject: [PATCH 04/17] Migration to PHP 8.1 under progress --- .github/workflows/php.yml | 32 +- .scrutinizer.yml | 4 +- .travis.sh | 10 +- .travis.yml | 7 +- README.md | 6 +- codeception.dist.yml | 42 +- composer.json | 101 +- docs/DockBlock.php | 4 +- src/Application/Application.php | 64 +- src/Application/Helper/Error.php | 10 +- src/Auth/AbstractIdentity.php | 4 +- src/Auth/Auth.php | 4 +- src/Auth/Model/AbstractRow.php | 16 +- src/Common/Container/ArrayAccess.php | 79 -- src/Common/Container/Container.php | 115 --- src/Common/Container/JsonSerialize.php | 32 - src/Common/Container/MagicAccess.php | 75 -- src/Common/Container/RegularAccess.php | 75 -- src/Common/Exception/CommonException.php | 6 - src/Common/Helper.php | 10 +- src/Common/Instance.php | 11 +- src/Common/Nil.php | 16 +- src/Common/Options.php | 8 +- src/Config/Config.php | 12 +- src/Config/ConfigLoader.php | 72 +- src/Controller/Controller.php | 32 +- src/Controller/Data.php | 10 +- src/Controller/Helper/Attachment.php | 3 +- src/Controller/Helper/CheckHttpAccept.php | 2 +- src/Controller/Helper/UseJson.php | 3 +- src/Controller/Mapper/AbstractMapper.php | 45 +- src/Controller/Mapper/Link.php | 14 +- src/Controller/Meta.php | 60 +- src/Crud/AbstractCrud.php | 2 +- src/Crud/CrudInterface.php | 8 +- src/Crud/Table.php | 6 +- src/Db/Db.php | 95 +- src/Db/Query/AbstractBuilder.php | 18 +- src/Db/Query/CompositeBuilder.php | 10 +- src/Db/Query/Delete.php | 2 +- src/Db/Query/Insert.php | 4 +- src/Db/Query/Select.php | 22 +- src/Db/Query/Traits/From.php | 50 +- src/Db/Query/Traits/Limit.php | 8 +- src/Db/Query/Traits/Order.php | 8 +- src/Db/Query/Traits/Set.php | 8 +- src/Db/Query/Traits/Where.php | 6 +- src/Db/Query/Update.php | 2 +- src/Db/Relations.php | 2 +- src/Db/Row.php | 6 +- src/Db/RowInterface.php | 2 +- src/Db/Table.php | 4 +- src/Db/TableInterface.php | 18 +- src/Db/Traits/RowRelations.php | 6 +- src/Db/Traits/TableProperty.php | 6 +- src/Db/Traits/TableRelations.php | 10 +- src/EventManager/Event.php | 74 +- src/EventManager/EventManager.php | 17 +- src/Grid/Data.php | 2 +- src/Grid/Grid.php | 16 +- src/Grid/Helper/Order.php | 2 +- src/Grid/Source/AbstractSource.php | 6 +- src/Grid/Source/ArraySource.php | 6 +- src/Grid/Source/SelectSource.php | 8 +- src/Grid/Source/SqlSource.php | 6 +- src/Http/CacheControl.php | 46 +- src/Http/Exception/BadRequestException.php | 6 +- src/Http/Exception/ForbiddenException.php | 5 +- src/Http/Exception/HttpException.php | 28 +- src/Http/Exception/NotAcceptableException.php | 5 +- src/Http/Exception/NotAllowedException.php | 5 +- src/Http/Exception/NotFoundException.php | 5 +- .../Exception/NotImplementedException.php | 5 +- src/Http/Exception/RedirectException.php | 8 +- src/Http/Exception/UnauthorizedException.php | 5 +- src/Http/RequestMethod.php | 27 +- src/Http/StatusCode.php | 263 ++--- src/Layout/Helper/BreadCrumbs.php | 2 +- src/Layout/Helper/HeadScript.php | 2 +- src/Layout/Layout.php | 7 +- src/Logger/Logger.php | 14 +- src/Mailer/Mailer.php | 8 +- src/Messages/Messages.php | 18 +- src/Proxy/Cache.php | 12 +- src/Proxy/Layout.php | 2 +- src/Proxy/ProxyTrait.php | 6 +- src/Proxy/Request.php | 25 +- src/Proxy/Response.php | 18 +- src/Registry/Registry.php | 2 +- src/Request/RequestFactory.php | 7 +- src/Response/AttachmentResponse.php | 10 +- src/Response/ContentType.php | 25 + src/Response/Response.php | 79 +- src/Response/ResponseTrait.php | 12 +- src/Router/Router.php | 6 +- src/Session/Adapter/AbstractAdapter.php | 8 +- src/Session/Adapter/Cache.php | 10 +- src/Session/Adapter/Redis.php | 14 +- src/Session/Session.php | 6 +- src/Translator/Translator.php | 14 +- .../Exception/ValidatorException.php | 9 +- src/Validator/README.md | 10 + src/Validator/Rule/AbstractCompareRule.php | 4 +- src/Validator/Rule/AbstractFilterRule.php | 4 +- src/Validator/Rule/AlphaRule.php | 2 +- src/Validator/Rule/ArrayRule.php | 4 +- src/Validator/Rule/BetweenInclusiveRule.php | 1 - src/Validator/Rule/BetweenRule.php | 6 +- src/Validator/Rule/CallbackRule.php | 4 +- src/Validator/Rule/ConditionRule.php | 2 +- src/Validator/Rule/ContainsRule.php | 2 +- src/Validator/Rule/ContainsStrictRule.php | 2 +- src/Validator/Rule/CountryCodeRule.php | 2 +- src/Validator/Rule/CreditCardRule.php | 4 +- src/Validator/Rule/DateRule.php | 2 +- src/Validator/Rule/DomainRule.php | 7 +- src/Validator/Rule/EmailRule.php | 2 +- src/Validator/Rule/EqualsRule.php | 2 +- src/Validator/Rule/EqualsStrictRule.php | 2 +- src/Validator/Rule/FloatRule.php | 2 +- src/Validator/Rule/InRule.php | 2 +- src/Validator/Rule/InStrictRule.php | 2 +- src/Validator/Rule/IntegerRule.php | 2 +- src/Validator/Rule/IpRule.php | 16 +- src/Validator/Rule/JsonRule.php | 2 +- src/Validator/Rule/LatinNumericRule.php | 2 +- src/Validator/Rule/LatinRule.php | 2 +- src/Validator/Rule/LengthRule.php | 4 +- src/Validator/Rule/LessRule.php | 2 +- src/Validator/Rule/MoreRule.php | 2 +- src/Validator/Rule/NegativeRule.php | 2 +- src/Validator/Rule/NoWhitespaceRule.php | 2 +- src/Validator/Rule/NotEmptyRule.php | 2 +- src/Validator/Rule/NumericRule.php | 2 +- src/Validator/Rule/PositiveRule.php | 2 +- src/Validator/Rule/RegexpRule.php | 2 +- src/Validator/Rule/RequiredRule.php | 2 +- src/Validator/Rule/RuleInterface.php | 2 +- src/Validator/Rule/SlugRule.php | 2 +- src/Validator/Rule/StringRule.php | 2 +- src/Validator/Rule/VersionRule.php | 2 +- src/Validator/Traits/Validator.php | 4 +- src/Validator/Validator.php | 4 +- src/Validator/ValidatorChain.php | 8 +- src/Validator/ValidatorForm.php | 10 +- src/Validator/ValidatorInterface.php | 6 +- src/View/Helper/Ahref.php | 10 +- src/View/Helper/Attributes.php | 6 +- src/View/Helper/Checkbox.php | 8 +- src/View/Helper/Exception.php | 5 +- src/View/Helper/Gravatar.php | 6 +- src/View/Helper/HasModule.php | 1 - src/View/Helper/HeadScript.php | 2 +- src/View/Helper/Redactor.php | 5 +- src/View/Helper/Script.php | 8 +- src/View/Helper/Select.php | 11 +- src/View/Helper/Style.php | 6 +- src/View/View.php | 18 +- src/View/ViewInterface.php | 2 +- src/_functions.php | 43 +- src/_loader.php | 4 - tests/_data/dump.sql | 132 +-- .../_generated/AcceptanceTesterActions.php | 960 ++++++++++++------ .../_generated/FunctionalTesterActions.php | 5 +- .../_support/_generated/UnitTesterActions.php | 879 ++++++++++------ tests/acceptance.suite.yml | 6 +- tests/functional.suite.yml | 6 +- tests/modules/error/controllers/index.php | 85 +- tests/modules/error/views/index.phtml | 12 +- tests/modules/index/controllers/index.php | 2 +- tests/modules/index/views/index.phtml | 34 +- tests/modules/test/controllers/mapper.php | 1 - .../test/controllers/route-with-param.php | 2 +- .../test/controllers/route-with-params.php | 4 +- .../test/controllers/throw-exception.php | 2 +- .../test/controllers/throw-forbidden.php | 2 +- tests/src/BootstrapTest.php | 29 +- tests/src/Fixtures/Crud/EmptyCrud.php | 5 +- tests/src/Fixtures/Crud/TableCrud.php | 2 +- tests/src/Fixtures/Models/Test/Crud.php | 2 +- tests/src/Fixtures/Models/Test/Row.php | 6 +- tests/src/Fixtures/Models/UserAdmin.php | 2 +- tests/src/Fixtures/Models/UserGuest.php | 2 +- .../Fixtures/Validator/Rule/CustomRule.php | 2 +- tests/src/FrameworkTestCase.php | 85 +- tests/unit.suite.yml | 14 +- tests/unit/Application/ApplicationTest.php | 11 +- tests/unit/Common/ContainerTest.php | 129 --- .../Common/Fixtures/Helper/HelperFunction.php | 6 +- .../Fixtures/Helper2/Helper2Function.php | 6 +- tests/unit/Common/SingletonTest.php | 8 + tests/unit/Config/ConfigLoaderTest.php | 68 +- tests/unit/Config/ConfigTest.php | 30 +- .../Fixtures/configs/emptyConfigsDir/.keep | 0 tests/unit/Controller/ControllerTest.php | 3 +- .../Controller/Fixtures/ConcreteWithData.php | 4 +- .../Fixtures/ConcreteWithoutReturn.php | 4 +- tests/unit/Controller/Mapper/CrudTest.php | 26 +- tests/unit/Controller/Mapper/RestTest.php | 18 +- tests/unit/Crud/TableTest.php | 4 +- tests/unit/EventManager/EventManagerTest.php | 4 +- tests/unit/EventManager/EventTest.php | 22 +- tests/unit/Registry/RegistryTest.php | 8 +- tests/unit/Router/RouterTest.php | 4 +- tests/unit/Validator/Rule/ConditionTest.php | 1 - tests/unit/Validator/Rule/MoreTest.php | 3 - tests/unit/Validator/ValidatorChainTest.php | 6 +- tests/unit/Validator/ValidatorFormTest.php | 7 +- 208 files changed, 2522 insertions(+), 2568 deletions(-) delete mode 100644 src/Common/Container/ArrayAccess.php delete mode 100644 src/Common/Container/Container.php delete mode 100644 src/Common/Container/JsonSerialize.php delete mode 100644 src/Common/Container/MagicAccess.php delete mode 100644 src/Common/Container/RegularAccess.php create mode 100644 src/Response/ContentType.php delete mode 100644 tests/unit/Common/ContainerTest.php delete mode 100644 tests/unit/Config/Fixtures/configs/emptyConfigsDir/.keep diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 65254b61..32bbb05c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,22 +12,22 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v2 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress + - uses: actions/checkout@v2 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" # Docs: https://getcomposer.org/doc/articles/scripts.md diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d118bc65..e884aac8 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -31,10 +31,10 @@ tools: standard: PSR12 php_cpd: enabled: true - excluded_dirs: [bin, data, docs, docker, public, tests, vendor] + excluded_dirs: [ bin, data, docs, docker, public, tests, vendor ] php_loc: enabled: true - excluded_dirs: [bin, data, docs, docker, public, tests, vendor] + excluded_dirs: [ bin, data, docs, docker, public, tests, vendor ] php_mess_detector: true php_pdepend: true sensiolabs_security_checker: true diff --git a/.travis.sh b/.travis.sh index 90a47b41..a8801fc0 100644 --- a/.travis.sh +++ b/.travis.sh @@ -13,20 +13,20 @@ if [ "$TRAVIS_REPO_SLUG" == "bluzphp/framework" ] && [ "$TRAVIS_TAG" != "" ] && echo "Publishing" # move docs to `home` directory - cp -R docs/html $HOME/docs-latest + cp -R docs/html "$HOME/docs-latest" - cd $HOME + cd "$HOME" || exit git config --global user.email "travis@travis-ci.com" git config --global user.name "travis-ci" git config --global push.default simple - git clone --quiet https://${GITHUB_TOKEN}@github.com/bluzphp/bluzphp.github.io > /dev/null + git clone --quiet "https://$GITHUB_TOKEN@github.com/bluzphp/bluzphp.github.io" > /dev/null - cd bluzphp.github.io + cd bluzphp.github.io || exit echo "-- Clean" git rm -rf ./ > /dev/null echo "-- Copy" - cp -Rf $HOME/docs-latest/* ./ + cp -Rf "$HOME"/docs-latest/* ./ echo "-- Push" git add -f . diff --git a/.travis.yml b/.travis.yml index fac73e5a..7411849a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: php php: - - 7.4 - 8.0 - 8.1 + - 8.2 services: - mysql matrix: allow_failures: - - php: 8.0 - - php: 8.1 + - php: 8.2 env: global: - XDEBUG_MODE=coverage @@ -51,4 +50,4 @@ notifications: - https://webhooks.gitter.im/e/c4fa557829c5bd992271 on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always - on_start: false # default: false + on_start: never # default: false diff --git a/README.md b/README.md index 002e54fd..1bbba510 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Easy to setup, easy to use. [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bluzphp/main) ## Achievements + [![PHP >= 7.2+](https://img.shields.io/packagist/php-v/bluzphp/framework.svg?style=flat)](https://php.net/) [![Latest Stable Version](https://img.shields.io/packagist/v/bluzphp/framework.svg?label=version&style=flat)](https://packagist.org/packages/bluzphp/framework) @@ -33,7 +34,10 @@ Auto-generating documentation is available at the http://bluzphp.github.io/ The project is developed by [NIX][3] PHP team and distributed under [MIT LICENSE][4] [1]: https://github.com/bluzphp/skeleton + [2]: https://github.com/bluzphp/framework/wiki -[3]: http://nixsolutions.com + +[3]: https://nixsolutions.com + [4]: https://raw.github.com/bluzphp/framework/master/LICENSE.md diff --git a/codeception.dist.yml b/codeception.dist.yml index 0ad783f9..b1e4cae0 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -1,27 +1,27 @@ actor: Tester bootstrap: _bootstrap.php paths: - tests: tests - log: tests/_output - data: tests/_data - support: tests/_support - envs: tests/_envs + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs settings: - colors: true - memory_limit: 1024M + colors: true + memory_limit: 1024M extensions: - enabled: - - Codeception\Extension\RunFailed + enabled: + - Codeception\Extension\RunFailed modules: - config: - Db: - dsn: 'mysql:host=localhost;dbname=bluz' - user: 'root' - password: '' - dump: tests/_data/dump.sql - PhpBrowser: - url: http://127.0.0.1:8000/ - REST: - url: http://127.0.0.1:8000/ - depends: PhpBrowser - part: Json + config: + Db: + dsn: 'mysql:host=localhost;dbname=bluz' + user: 'root' + password: '' + dump: tests/_data/dump.sql + PhpBrowser: + url: http://127.0.0.1:8000/ + REST: + url: http://127.0.0.1:8000/ + depends: PhpBrowser + part: Json diff --git a/composer.json b/composer.json index ca6daa82..d71ea30d 100644 --- a/composer.json +++ b/composer.json @@ -1,52 +1,55 @@ { - "name": "bluzphp/framework", - "description": "Lightweight PHP framework", - "type": "library", - "require": { - "php": ">=8.0", - "ext-PDO": "*", - "ext-pdo_mysql": "*", - "ext-json": "*", - "ext-ctype": "*", - "bluzphp/collection": "~1.0", - "psr/log": "~1.1", - "laminas/laminas-diactoros": "~2.6", - "laminas/laminas-httphandlerrunner": "~1.4", - "symfony/cache": "^5.3" + "name": "bluzphp/framework", + "description": "Lightweight PHP framework", + "type": "library", + "require": { + "php": ">=8.1", + "ext-ctype": "*", + "ext-fileinfo": "*", + "ext-json": "*", + "ext-pdo": "*", + "ext-pdo_mysql": "*", + "bluzphp/collection": "~1.0", + "bluzphp/container": "~1.0", + "phpmailer/phpmailer": "~6.7", + "psr/log": "^2.0", + "laminas/laminas-diactoros": "~2.24", + "laminas/laminas-httphandlerrunner": "~2.5", + "symfony/cache": "~6.2" + }, + "require-dev": { + "codeception/codeception": "~5.0", + "codeception/module-asserts": "~3.0", + "codeception/module-phpbrowser": "~2.0", + "php-coveralls/php-coveralls": "~2.5", + "squizlabs/php_codesniffer": "~3.7", + "phploc/phploc": "~7.0" + }, + "suggest": { + "ext-gettext": "required by Bluz\\Translator (https://github.com/bluzphp/framework/wiki/Translator)", + "ext-redis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)", + "ext-memcached": "required by Memcached adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)", + "phpmailer/phpmailer": "required by Bluz\\Mailer (https://github.com/bluzphp/framework/wiki/Mailer)", + "predis/predis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)" + }, + "autoload": { + "psr-4": { + "Bluz\\": "src/" }, - "require-dev": { - "codeception/codeception": "~4.1", - "codeception/module-asserts": "~1.3", - "codeception/module-phpbrowser": "~1.0", - "php-coveralls/php-coveralls": "~2.4", - "squizlabs/php_codesniffer": "~3.6", - "phploc/phploc": "~7.0" - }, - "suggest": { - "ext-gettext": "required by Bluz\\Translator (https://github.com/bluzphp/framework/wiki/Translator)", - "ext-redis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)", - "ext-memcached": "required by Memcached adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)", - "phpmailer/phpmailer": "required by Bluz\\Mailer (https://github.com/bluzphp/framework/wiki/Mailer)", - "predis/predis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)" - }, - "autoload": { - "psr-4": { - "Bluz\\": "src/" - }, - "files": [ - "src/_functions.php", - "src/_loader.php" - ] - }, - "authors": [ - { - "name": "Bluz Framework Contributors", - "homepage": "https://github.com/bluzphp/framework/graphs/contributors" - } - ], - "support": { - "issues": "https://github.com/bluzphp/framework/issues", - "wiki": "https://github.com/bluzphp/framework/wiki" - }, - "license": "MIT" + "files": [ + "src/_functions.php", + "src/_loader.php" + ] + }, + "authors": [ + { + "name": "Bluz Framework Contributors", + "homepage": "https://github.com/bluzphp/framework/graphs/contributors" + } + ], + "support": { + "issues": "https://github.com/bluzphp/framework/issues", + "wiki": "https://github.com/bluzphp/framework/wiki" + }, + "license": "MIT" } diff --git a/docs/DockBlock.php b/docs/DockBlock.php index 862a039e..34f16fb8 100644 --- a/docs/DockBlock.php +++ b/docs/DockBlock.php @@ -170,8 +170,8 @@ class DockBlock * @.since [version] [] * @.deprecated [version] [] * - * @param string $arg1 the string to quote - * @param int $arg2 an integer of how many problems happened. + * @param string $arg1 the string to quote + * @param int $arg2 an integer of how many problems happened. * Indent to the description's starting point * for long ones. * diff --git a/src/Application/Application.php b/src/Application/Application.php index 1efda518..dde8a18e 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -32,6 +32,7 @@ use Bluz\Proxy\Translator; use Bluz\Request\RequestFactory; use Bluz\Response\Response as ResponseInstance; +use Bluz\Response\ContentType; use Exception; use InvalidArgumentException; use ReflectionClass; @@ -61,9 +62,9 @@ class Application protected string $environment = 'production'; /** - * @var string Application path + * @var string|null Application path */ - protected string $path; + protected ?string $path = null; /** * @var bool Debug application flag @@ -89,21 +90,48 @@ public function getEnvironment(): string * Get path to Application * * @return string + * @throws ApplicationException */ public function getPath(): string { if (!$this->path) { - if (defined('PATH_APPLICATION')) { - $this->path = PATH_APPLICATION; - } else { - $reflection = new ReflectionClass($this); - // 3 level up - $this->path = dirname($reflection->getFileName(), 3); - } + $this->setPath( + $this->detectPath() + ); } return $this->path; } + /** + * @param string $environment + */ + public function setEnvironment(string $environment): void + { + $this->environment = $environment; + } + + /** + * @param string $path + * @throws ApplicationException + */ + public function setPath(string $path): void + { + if (!is_readable($path)) { + throw new ApplicationException('Application path is not readable'); + } + $this->path = $path; + } + + /** + * Try to detect path of the Application + * @return string + */ + protected function detectPath(): string + { + $reflection = new ReflectionClass($this); + return dirname($reflection->getFileName(), 3); // 3 level up + } + /** * Return Debug flag * @@ -133,15 +161,11 @@ public function useLayout(?bool $flag = null): bool /** * Initialize system packages * - * @param string $environment - * * @return void * @throws ApplicationException */ - public function init(string $environment = 'production'): void + public function init(): void { - $this->environment = $environment; - try { // initial default helper path $this->addHelperPath(__DIR__ . '/Helper/'); @@ -179,13 +203,15 @@ public function init(string $environment = 'production'): void * * @return void * @throws ConfigException + * @throws ApplicationException */ protected function initConfig(): void { $loader = new ConfigLoader(); - $loader->setPath($this->getPath()); - $loader->setEnvironment($this->getEnvironment()); - $loader->load(); + // load default configuration + $loader->load($this->getPath() .'/configs/default'); + // and merge it with environment configuration + $loader->load($this->getPath() .'/configs/'. $this->getEnvironment()); $config = new \Bluz\Config\Config(); $config->setFromArray($loader->getConfig()); @@ -327,7 +353,7 @@ protected function preProcess(): void // switch to JSON response based on Accept header if (Request::checkAccept([Request::TYPE_HTML, Request::TYPE_JSON]) === Request::TYPE_JSON) { $this->layoutFlag = false; - Response::setType('JSON'); + Response::setContentType(ContentType::JSON); } } @@ -390,7 +416,7 @@ protected function postProcess(): void * * @param string $module * @param string $controller - * @param array $params + * @param array $params * * @return Controller * @throws CommonException diff --git a/src/Application/Helper/Error.php b/src/Application/Helper/Error.php index 283828b1..61a98da3 100644 --- a/src/Application/Helper/Error.php +++ b/src/Application/Helper/Error.php @@ -16,6 +16,7 @@ use Bluz\Common\Exception\ComponentException; use Bluz\Controller\Controller; use Bluz\Controller\ControllerException; +use Bluz\Http\Exception\HttpException; use Bluz\Proxy\Response; use Bluz\Proxy\Router; use Exception; @@ -42,7 +43,14 @@ function (Exception $exception) { $module = Router::getErrorModule(); $controller = Router::getErrorController(); - $params = ['code' => $exception->getCode(), 'exception' => $exception]; + + if ($exception instanceof HttpException) { + $code = $exception->getStatusCode()->value; + } else { + $code = $exception->getCode(); + } + + $params = ['code' => $code, 'exception' => $exception]; return $this->dispatch($module, $controller, $params); }; diff --git a/src/Auth/AbstractIdentity.php b/src/Auth/AbstractIdentity.php index da5dd924..e3b7ed04 100644 --- a/src/Auth/AbstractIdentity.php +++ b/src/Auth/AbstractIdentity.php @@ -19,8 +19,8 @@ * @package Bluz\Auth * * @property integer $id - * @property string $login - * @property string $email + * @property string $login + * @property string $email */ abstract class AbstractIdentity extends Row implements IdentityInterface { diff --git a/src/Auth/Auth.php b/src/Auth/Auth.php index 184f5684..509b7b35 100644 --- a/src/Auth/Auth.php +++ b/src/Auth/Auth.php @@ -29,12 +29,12 @@ class Auth /** * @var ?IdentityInterface Instance of EntityInterface */ - protected ?IdentityInterface $identity; + protected ?IdentityInterface $identity = null; /** * Setup identity * - * @param IdentityInterface $identity + * @param IdentityInterface $identity * * @return void */ diff --git a/src/Auth/Model/AbstractRow.php b/src/Auth/Model/AbstractRow.php index 9895b79d..518b2a12 100644 --- a/src/Auth/Model/AbstractRow.php +++ b/src/Auth/Model/AbstractRow.php @@ -20,14 +20,14 @@ * @author Anton Shevchuk * * @property integer $userId - * @property string $provider - * @property string $foreignKey - * @property string $token - * @property string $tokenSecret - * @property string $tokenType - * @property string $created - * @property string $updated - * @property string $expired + * @property string $provider + * @property string $foreignKey + * @property string $token + * @property string $tokenSecret + * @property string $tokenType + * @property string $created + * @property string $updated + * @property string $expired */ abstract class AbstractRow extends Row { diff --git a/src/Common/Container/ArrayAccess.php b/src/Common/Container/ArrayAccess.php deleted file mode 100644 index a10bde89..00000000 --- a/src/Common/Container/ArrayAccess.php +++ /dev/null @@ -1,79 +0,0 @@ -doSetContainer($offset, $value); - } - - /** - * Offset to retrieve - * - * @param mixed $offset - * - * @return mixed - */ - public function offsetGet(mixed $offset): mixed - { - return $this->doGetContainer($offset); - } - - /** - * Whether a offset exists - * - * @param mixed $offset - * - * @return bool - */ - public function offsetExists(mixed $offset): bool - { - return $this->doContainsContainer($offset); - } - - /** - * Offset to unset - * - * @param mixed $offset - */ - public function offsetUnset(mixed $offset): void - { - $this->doDeleteContainer($offset); - } -} diff --git a/src/Common/Container/Container.php b/src/Common/Container/Container.php deleted file mode 100644 index b9b8844e..00000000 --- a/src/Common/Container/Container.php +++ /dev/null @@ -1,115 +0,0 @@ -container[$key] = $value; - } - - /** - * Get value by key - * - * @param string $key - * - * @return mixed - */ - protected function doGetContainer(string $key): mixed - { - if ($this->doContainsContainer($key)) { - return $this->container[$key]; - } - return null; - } - - /** - * Check contains key in container - * - * @param string $key - * - * @return bool - */ - protected function doContainsContainer(string $key): bool - { - return array_key_exists($key, $this->container); - } - - /** - * Delete value by key - * - * @param string $key - * - * @return void - */ - protected function doDeleteContainer(string $key): void - { - unset($this->container[$key]); - } - - /** - * Sets all data in the row from an array - * - * @param array $data - * - * @return void - */ - public function setFromArray(array $data): void - { - foreach ($data as $key => $value) { - $this->container[$key] = $value; - } - } - - /** - * Returns the column/value data as an array - * - * @return array - */ - public function toArray(): array - { - return $this->container; - } - - /** - * Reset container array - * - * @return void - */ - public function resetArray(): void - { - foreach ($this->container as &$value) { - $value = null; - } - } -} diff --git a/src/Common/Container/JsonSerialize.php b/src/Common/Container/JsonSerialize.php deleted file mode 100644 index 656dae15..00000000 --- a/src/Common/Container/JsonSerialize.php +++ /dev/null @@ -1,32 +0,0 @@ -toArray(); - } -} diff --git a/src/Common/Container/MagicAccess.php b/src/Common/Container/MagicAccess.php deleted file mode 100644 index 172a9cfa..00000000 --- a/src/Common/Container/MagicAccess.php +++ /dev/null @@ -1,75 +0,0 @@ -doSetContainer($key, $value); - } - - /** - * Magic alias for get() regular method - * - * @param string $key - * - * @return mixed - */ - public function __get(string $key) - { - return $this->doGetContainer($key); - } - - /** - * Magic alias for contains() regular method - * - * @param string $key - * - * @return bool - */ - public function __isset(string $key): bool - { - return $this->doContainsContainer($key); - } - - /** - * Magic alias for delete() regular method - * - * @param string $key - * - * @return void - */ - public function __unset(string $key): void - { - $this->doDeleteContainer($key); - } -} diff --git a/src/Common/Container/RegularAccess.php b/src/Common/Container/RegularAccess.php deleted file mode 100644 index d6b56b40..00000000 --- a/src/Common/Container/RegularAccess.php +++ /dev/null @@ -1,75 +0,0 @@ -doSetContainer($key, $value); - } - - /** - * Get value by key - * - * @param string $key - * - * @return mixed - */ - public function get(string $key): mixed - { - return $this->doGetContainer($key); - } - - /** - * Check contains key in container - * - * @param string $key - * - * @return bool - */ - public function contains(string $key): bool - { - return $this->doContainsContainer($key); - } - - /** - * Delete value by key - * - * @param string $key - * - * @return void - */ - public function delete(string $key): void - { - $this->doDeleteContainer($key); - } -} diff --git a/src/Common/Exception/CommonException.php b/src/Common/Exception/CommonException.php index d77a9971..0fbabe35 100644 --- a/src/Common/Exception/CommonException.php +++ b/src/Common/Exception/CommonException.php @@ -11,8 +11,6 @@ namespace Bluz\Common\Exception; -use Bluz\Http\StatusCode; - /** * Basic Exception for Bluz framework * @@ -21,8 +19,4 @@ */ class CommonException extends \Exception { - /** - * @var integer Used as default HTTP code for exceptions - */ - protected $code = StatusCode::INTERNAL_SERVER_ERROR; } diff --git a/src/Common/Helper.php b/src/Common/Helper.php index cf1ff906..6bd73ee5 100644 --- a/src/Common/Helper.php +++ b/src/Common/Helper.php @@ -36,7 +36,7 @@ trait Helper /** * Add helper path * - * @param string $path + * @param string $path * * @return void * @throws CommonException @@ -63,8 +63,8 @@ public function addHelperPath(string $path): void /** * Call magic helper * - * @param string $method - * @param array $arguments + * @param string $method + * @param array $arguments * * @return mixed * @throws CommonException @@ -114,8 +114,8 @@ private function loadHelper(string $name): void /** * Add helper callable * - * @param string $name - * @param string $path + * @param string $name + * @param string $path * * @return void * @throws CommonException diff --git a/src/Common/Instance.php b/src/Common/Instance.php index 594d3103..6644f321 100644 --- a/src/Common/Instance.php +++ b/src/Common/Instance.php @@ -19,16 +19,17 @@ */ trait Instance { + protected static array $instances = []; + /** * Get instance * @return static */ - public static function getInstance() + public static function getInstance(): static { - static $instance; - if (null === $instance) { - $instance = new static(); + if (!isset(static::$instances[static::class])) { + static::$instances[static::class] = new static(); } - return $instance; + return static::$instances[static::class]; } } diff --git a/src/Common/Nil.php b/src/Common/Nil.php index ba575e1a..690efbc7 100644 --- a/src/Common/Nil.php +++ b/src/Common/Nil.php @@ -26,8 +26,8 @@ class Nil /** * Magic call * - * @param string $method - * @param array $args + * @param string $method + * @param array $args * * @return null */ @@ -39,8 +39,8 @@ public function __call($method, $args) /** * Magic call for static * - * @param string $method - * @param array $args + * @param string $method + * @param array $args * * @return null */ @@ -52,7 +52,7 @@ public static function __callStatic($method, $args) /** * Magic __get * - * @param string $key + * @param string $key * * @return null */ @@ -64,8 +64,8 @@ public function __get($key) /** * Magic __set * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * * @return null */ @@ -77,7 +77,7 @@ public function __set($key, $value) /** * Magic __isset * - * @param string $key + * @param string $key * * @return false */ diff --git a/src/Common/Options.php b/src/Common/Options.php index c2ca1a23..a74845b0 100644 --- a/src/Common/Options.php +++ b/src/Common/Options.php @@ -52,8 +52,8 @@ trait Options /** * Get option by key * - * @param string $key - * @param array $keys + * @param string $key + * @param array $keys * * @return mixed */ @@ -69,8 +69,8 @@ public function getOption(string $key, ...$keys): mixed /** * Set option by key over setter * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * * @return void */ diff --git a/src/Config/Config.php b/src/Config/Config.php index 508ff0b2..57fb4cb2 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -12,8 +12,8 @@ namespace Bluz\Config; use Bluz\Collection\Collection; -use Bluz\Common\Container\Container; -use Bluz\Common\Container\RegularAccess; +use Bluz\Container\Container; +use Bluz\Container\RegularAccess; /** * Config @@ -30,22 +30,22 @@ class Config /** * Return configuration by key * - * @param string|array $key + * @param array $keys * * @return array|mixed * @throws ConfigException */ - public function get($key): mixed + public function get(...$keys): mixed { // configuration is missed if (empty($this->container)) { throw new ConfigException('System configuration is missing'); } - if (!count($key)) { + if (!count($keys)) { return $this->container; } - return Collection::get($this->container, ...$key); + return Collection::get($this->container, ...$keys); } } diff --git a/src/Config/ConfigLoader.php b/src/Config/ConfigLoader.php index c376c2cb..393f49cc 100644 --- a/src/Config/ConfigLoader.php +++ b/src/Config/ConfigLoader.php @@ -26,17 +26,7 @@ class ConfigLoader /** * @var array configuration data */ - protected array $config; - - /** - * @var string path to configuration files - */ - protected string $path; - - /** - * @var string environment - */ - protected string $environment; + protected array $config = []; /** * @return array @@ -47,67 +37,23 @@ public function getConfig(): array } /** - * @return string - */ - public function getPath(): string - { - return $this->path; - } - - /** - * Set path to configuration files + * Load and merge configuration * * @param string $path - * * @return void * @throws ConfigException */ - public function setPath(string $path): void + public function load(string $path): void { - if (!is_dir($path)) { - throw new ConfigException('Configuration directory is not exists'); + if (!$path) { + throw new ConfigException('Configuration directory is required'); } - $this->path = rtrim($path, '/'); - } - - /** - * @return string - */ - public function getEnvironment(): string - { - return $this->environment; - } - - /** - * Set application environment - * - * @param string $environment - * - * @return void - */ - public function setEnvironment(string $environment): void - { - $this->environment = $environment; - } - /** - * Load configuration - * - * @return void - * @throws ConfigException - */ - public function load(): void - { - if (!$this->path) { - throw new ConfigException('Configuration directory is not setup'); + if (!is_dir($path)) { + throw new ConfigException('Configuration directory is not exists'); } - $this->config = $this->loadFiles($this->path . '/configs/default'); - - if ($this->environment) { - $customConfig = $this->loadFiles($this->path . '/configs/' . $this->environment); - $this->config = array_replace_recursive($this->config, $customConfig); - } + $this->config = array_replace_recursive($this->config, $this->loadFiles($path)); } /** @@ -118,7 +64,7 @@ public function load(): void * @return mixed * @throws ConfigException */ - protected function loadFile(string $path) + protected function loadFile(string $path): mixed { if (!is_file($path) && !is_readable($path)) { throw new ConfigException("Configuration file `$path` not found"); diff --git a/src/Controller/Controller.php b/src/Controller/Controller.php index 94a1430a..6c82c7d0 100644 --- a/src/Controller/Controller.php +++ b/src/Controller/Controller.php @@ -56,49 +56,49 @@ class Controller implements JsonSerializable /** * @var string */ - protected $mzodule; + protected string $module; /** * @var string */ - protected $controller; + protected string $controller; /** * @var array */ - protected $params; + protected array $params; /** * @var string Cache key */ - protected $key; + protected string $key; /** - * @var string Template name, by default is equal to controller name + * @var string|null Template name, by default is equal to controller name */ - protected $template; + protected ?string $template; /** - * @var string + * @var string|null */ - protected $file; + protected ?string $file = null; /** - * @var Meta + * @var Meta|null */ - protected $meta; + protected ?Meta $meta = null; /** - * @var Data + * @var Data|null */ - protected $data; + protected ?Data $data = null; /** * Constructor of Statement * * @param string $module * @param string $controller - * @param array $params + * @param array $params * * @throws CommonException */ @@ -164,7 +164,7 @@ protected function setParams(array $params): void } /** - * @return string + * @return string|null */ public function getTemplate(): ?string { @@ -328,8 +328,8 @@ public function getMeta(): Meta /** * Assign key/value pair to Data object * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * * @return void */ diff --git a/src/Controller/Data.php b/src/Controller/Data.php index d377bbed..e053d535 100644 --- a/src/Controller/Data.php +++ b/src/Controller/Data.php @@ -11,11 +11,11 @@ namespace Bluz\Controller; -use Bluz\Common\Container\ArrayAccess; -use Bluz\Common\Container\Container; -use Bluz\Common\Container\JsonSerialize; -use Bluz\Common\Container\MagicAccess; -use Bluz\Common\Container\RegularAccess; +use Bluz\Container\ArrayAccess; +use Bluz\Container\Container; +use Bluz\Container\JsonSerialize; +use Bluz\Container\MagicAccess; +use Bluz\Container\RegularAccess; /** * Data diff --git a/src/Controller/Helper/Attachment.php b/src/Controller/Helper/Attachment.php index 54358dd3..1bc54e96 100644 --- a/src/Controller/Helper/Attachment.php +++ b/src/Controller/Helper/Attachment.php @@ -13,6 +13,7 @@ use Bluz\Controller\Controller; use Bluz\Proxy\Response; +use Bluz\Response\ContentType; /** * Switch layout @@ -24,7 +25,7 @@ function ($file) { /** * @var Controller $this */ - Response::setType('FILE'); + Response::setContentType(ContentType::FILE); $this->assign('FILE', $file); $this->disableLayout(); $this->disableView(); diff --git a/src/Controller/Helper/CheckHttpAccept.php b/src/Controller/Helper/CheckHttpAccept.php index e44c3fe2..fa73c047 100644 --- a/src/Controller/Helper/CheckHttpAccept.php +++ b/src/Controller/Helper/CheckHttpAccept.php @@ -34,7 +34,7 @@ function () { */ $allowAccept = $this->getMeta()->getAccept(); - // some controllers hasn't @accept tag + // some controllers haven't @accept tag if (!$allowAccept) { // but by default allow just HTML output $allowAccept = [Request::TYPE_HTML, Request::TYPE_ANY]; diff --git a/src/Controller/Helper/UseJson.php b/src/Controller/Helper/UseJson.php index a3b0d260..915df654 100644 --- a/src/Controller/Helper/UseJson.php +++ b/src/Controller/Helper/UseJson.php @@ -14,6 +14,7 @@ use Bluz\Application\Application; use Bluz\Controller\Controller; use Bluz\Proxy\Response; +use Bluz\Response\ContentType; /** * Switch to JSON content @@ -26,5 +27,5 @@ function () { * @var Controller $this */ Application::getInstance()->useLayout(false); - Response::setType('JSON'); + Response::setContentType(ContentType::JSON); }; diff --git a/src/Controller/Mapper/AbstractMapper.php b/src/Controller/Mapper/AbstractMapper.php index f0447c2a..7aa6d331 100644 --- a/src/Controller/Mapper/AbstractMapper.php +++ b/src/Controller/Mapper/AbstractMapper.php @@ -36,49 +36,49 @@ abstract class AbstractMapper { /** - * @var string HTTP Method + * @var RequestMethod HTTP Method */ - protected $method = RequestMethod::GET; + protected RequestMethod $method = RequestMethod::GET; /** * @var string */ - protected $module; + protected string $module; /** * @var string */ - protected $controller; + protected string $controller; /** * @var array identifier */ - protected $primary; + protected array $primary; /** - * @var string relation list + * @var ?string relation list */ - protected $relation; + protected ?string $relation = null; /** - * @var string relation Id + * @var ?string relation ID */ - protected $relationId; + protected ?string $relationId = null; /** * @var array params of query */ - protected $params = []; + protected array $params = []; /** * @var array query data */ - protected $data = []; + protected array $data = []; /** * @var AbstractCrud instance of CRUD */ - protected $crud; + protected AbstractCrud $crud; /** * [ @@ -92,7 +92,7 @@ abstract class AbstractMapper * * @var Link[] */ - protected $map = []; + protected array $map = []; /** * Prepare params @@ -112,15 +112,15 @@ public function __construct(AbstractCrud $crud) /** * Add mapping data * - * @param string $method + * @param RequestMethod $method * @param string $module * @param string $controller * * @return Link */ - public function addMap(string $method, string $module, string $controller): Link + public function addMap(RequestMethod $method, string $module, string $controller): Link { - return $this->map[strtoupper($method)] = new Link($module, $controller); + return $this->map[$method->value] = new Link($module, $controller); } /** @@ -252,15 +252,14 @@ public function run(): Controller protected function prepareRequest(): void { // HTTP method - $method = Request::getMethod(); - $this->method = strtoupper($method); + $method = strtoupper(Request::getMethod()); + $this->method = RequestMethod::tryFrom($method); // get path // %module% / %controller% / %id% / %relation% / %id% $path = Router::getCleanUri(); $this->params = explode('/', rtrim($path, '/')); - // module $this->module = array_shift($this->params); @@ -292,11 +291,11 @@ protected function prepareRequest(): void protected function dispatch() { // check implementation - if (!isset($this->map[$this->method])) { + if (!isset($this->map[$this->method->value])) { throw new NotImplementedException(); } - $link = $this->map[$this->method]; + $link = $this->map[$this->method->value]; // check permissions if (!Acl::isAllowed($this->module, $link->getAcl())) { @@ -306,12 +305,10 @@ protected function dispatch() $this->crud->setFields($link->getFields()); // dispatch controller - $result = Application::getInstance()->dispatch( + return Application::getInstance()->dispatch( $link->getModule(), $link->getController(), $this->prepareParams() ); - - return $result; } } diff --git a/src/Controller/Mapper/Link.php b/src/Controller/Mapper/Link.php index 9ba97d4b..cb61c28b 100644 --- a/src/Controller/Mapper/Link.php +++ b/src/Controller/Mapper/Link.php @@ -22,22 +22,22 @@ class Link /** * @var string */ - protected $module; + protected string $module; /** * @var string */ - protected $controller; + protected string $controller; /** - * @var string + * @var string|null */ - protected $acl; + protected ?string $acl = null; /** * @var array */ - protected $fields = []; + protected array $fields = []; /** * Constructor of Link @@ -78,7 +78,7 @@ public function fields(array $fields): Link } /** - * @return string + * @return string|null */ public function getModule(): ?string { @@ -94,7 +94,7 @@ protected function setModule(string $module): void } /** - * @return string + * @return string|null */ public function getController(): ?string { diff --git a/src/Controller/Meta.php b/src/Controller/Meta.php index e443312d..c20feef6 100644 --- a/src/Controller/Meta.php +++ b/src/Controller/Meta.php @@ -30,54 +30,54 @@ class Meta /** * @var string full path to file */ - protected $file; + protected string $file; /** - * @var integer cache TTL + * @var int cache TTL */ - protected $cache = 0; + protected int $cache = 0; /** * @var array list of Accept */ - protected $accept = []; + protected array $accept = []; /** * @var array list of Acl */ - protected $acl = []; + protected array $acl = []; /** * @var array list of HTTP methods */ - protected $method = []; + protected array $method = []; /** * @var array described params */ - protected $params = []; + protected array $params = []; /** - * @var string privilege + * @var ?string privilege */ - protected $privilege; + protected ?string $privilege = null; /** * @var array routers */ - protected $route = []; + protected array $route = []; /** * @var array default values of params */ - protected $values = []; + protected array $values = []; /** * Constructor of Reflection * * @param string $file */ - public function __construct($file) + public function __construct(string $file) { $this->file = $file; } @@ -85,7 +85,7 @@ public function __construct($file) /** * Set state required for working with var_export (used inside PHP File cache) * - * @param array $array + * @param array $array * * @return Meta */ @@ -120,7 +120,7 @@ public function process(): void $docComment = $reflection->getDocComment(); // get all options by one regular expression - if (preg_match_all('/\s*\*\s*\@([a-z0-9-_]+)\s+(.*).*\s+/i', $docComment, $matches)) { + if (preg_match_all('/\s*\*\s*@([a-z0-9-_]+)\s+(.*).*\s+/i', $docComment, $matches)) { foreach ($matches[1] as $i => $key) { $this->setOption($key, trim($matches[2][$i])); } @@ -160,28 +160,14 @@ public function params(array $requestParams): array $params = []; foreach ($this->params as $param => $type) { if (isset($requestParams[$param])) { - switch ($type) { - case 'bool': - case 'boolean': - $params[] = (bool)$requestParams[$param]; - break; - case 'int': - case 'integer': - $params[] = (int)$requestParams[$param]; - break; - case 'float': - $params[] = (float)$requestParams[$param]; - break; - case 'string': - $params[] = (string)$requestParams[$param]; - break; - case 'array': - $params[] = (array)$requestParams[$param]; - break; - default: - $params[] = $requestParams[$param]; - break; - } + $params[] = match ($type) { + 'bool', 'boolean' => (bool)$requestParams[$param], + 'int', 'integer' => (int)$requestParams[$param], + 'float' => (float)$requestParams[$param], + 'string' => (string)$requestParams[$param], + 'array' => (array)$requestParams[$param], + default => $requestParams[$param], + }; } elseif (isset($this->values[$param])) { $params[] = $this->values[$param]; } else { @@ -271,7 +257,7 @@ public function getAccept(): ?array */ public function setAccept(string $accept): void { - // allow accept map + // accept map $acceptMap = [ 'ANY' => Request::TYPE_ANY, 'HTML' => Request::TYPE_HTML, diff --git a/src/Crud/AbstractCrud.php b/src/Crud/AbstractCrud.php index ba40b7b6..94b30bee 100644 --- a/src/Crud/AbstractCrud.php +++ b/src/Crud/AbstractCrud.php @@ -30,7 +30,7 @@ abstract class AbstractCrud implements CrudInterface * @var array Fields for action * @todo should be different for Create, Read and Update */ - protected $fields = []; + protected array $fields = []; /** * Return primary key signature diff --git a/src/Crud/CrudInterface.php b/src/Crud/CrudInterface.php index abe829fd..dd09c7a4 100644 --- a/src/Crud/CrudInterface.php +++ b/src/Crud/CrudInterface.php @@ -30,7 +30,7 @@ interface CrudInterface /** * Get item by primary key(s) * - * @param mixed $primary + * @param mixed $primary * * @return mixed */ @@ -39,8 +39,8 @@ public function readOne($primary); /** * Get collection of items * - * @param integer $offset - * @param integer $limit + * @param int $offset + * @param int $limit * @param array $params * * @return array[Row[], integer] @@ -87,7 +87,7 @@ public function updateSet(array $data); /** * Delete item * - * @param mixed $primary + * @param mixed $primary * * @return integer */ diff --git a/src/Crud/Table.php b/src/Crud/Table.php index 339b65cc..297f3fdc 100644 --- a/src/Crud/Table.php +++ b/src/Crud/Table.php @@ -43,7 +43,7 @@ public function getPrimaryKey(): array /** * Get record from Db or create new object * - * @param mixed $primary + * @param mixed $primary * * @return Db\RowInterface * @throws TableNotFoundException @@ -147,7 +147,7 @@ public function createOne(array $data) /** * Update item * - * @param mixed $primary + * @param mixed $primary * @param array $data * * @return integer @@ -170,7 +170,7 @@ public function updateOne($primary, array $data) /** * Delete item * - * @param mixed $primary + * @param mixed $primary * * @return integer * @throws NotFoundException diff --git a/src/Db/Db.php b/src/Db/Db.php index 6f47b5c3..e085e033 100644 --- a/src/Db/Db.php +++ b/src/Db/Db.php @@ -57,9 +57,9 @@ class Db ]; /** - * @var ?PDO PDO instance + * @var PDO|null PDO instance */ - protected ?PDO $handler; + protected ?PDO $handler = null; /** * Setup connection @@ -75,10 +75,10 @@ class Db * ]); * * - * @param array $connect options + * @param array $connect options * - * @throws ConfigurationException * @return void + * @throws ConfigurationException */ public function setConnect(array $connect): void { @@ -94,8 +94,7 @@ public function setConnect(array $connect): void */ private function checkConnect(): void { - if ( - empty($this->connect['type']) || + if (empty($this->connect['type']) || empty($this->connect['host']) || empty($this->connect['name']) || empty($this->connect['user']) @@ -110,7 +109,7 @@ private function checkConnect(): void /** * Setup attributes for PDO connect * - * @param array $attributes + * @param array $attributes * * @return void */ @@ -177,14 +176,14 @@ public function handler(): PDO /** * Prepare SQL query and return PDO Statement * - * @param string $sql SQL query with placeholders - * @param array $params params for query placeholders + * @param string $sql SQL query with placeholders + * @param array $params params for query placeholders * + * @return PDOStatement + * @throws DbException * @todo Switch to PDO::activeQueryString() when it will be possible * @link https://wiki.php.net/rfc/debugging_pdo_prepared_statement_emulation * - * @return PDOStatement - * @throws DbException */ protected function prepare(string $sql, array $params = []): PDOStatement { @@ -204,8 +203,8 @@ protected function prepare(string $sql, array $params = []): PDOStatement * $db->quote($_GET['id']) * * - * @param string $value - * @param int $type + * @param string $value + * @param int $type * * @return string * @throws DbException @@ -218,7 +217,7 @@ public function quote(string $value, int $type = PDO::PARAM_STR): string /** * Quote a string so it can be safely used as a table or column name * - * @param string $identifier + * @param string $identifier * * @return string */ @@ -243,11 +242,11 @@ public function quoteIdentifier(string $identifier): string * $db->query("SET NAMES 'utf8'"); * * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "UPDATE users SET name = :name WHERE id = :id" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':name' => 'John', ':id' => '123') - * @param array $types Types of params (optional) + * @param array $types Types of params (optional) * array (':name' => \PDO::PARAM_STR, ':id' => \PDO::PARAM_INT) * * @return integer the number of rows @@ -286,7 +285,7 @@ public function select(...$select): Query\Select /** * Create new query insert builder * - * @param string $table + * @param string $table * * @return Query\Insert */ @@ -300,7 +299,7 @@ public function insert(string $table): Query\Insert /** * Create new query update builder * - * @param string $table + * @param string $table * * @return Query\Update */ @@ -314,7 +313,7 @@ public function update(string $table): Query\Update /** * Create new query update builder * - * @param string $table + * @param string $table * * @return Query\Delete */ @@ -333,9 +332,9 @@ public function delete(string $table): Query\Delete * $db->fetchOne("SELECT COUNT(*) FROM users"); * * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT * FROM users WHERE name = :name AND pass = :pass" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':name' => 'John', ':pass' => '123456') * * @return string|false @@ -360,9 +359,9 @@ public function fetchOne(string $sql, array $params = []) * $db->fetchRow("SELECT name, email FROM users WHERE id = :id", [':id'=>$id]); * * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT * FROM users WHERE name = :name AND pass = :pass" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':name' => 'John', ':pass' => '123456') * * @return array|false array ('name' => 'John', 'email' => 'john@smith.com') @@ -385,9 +384,9 @@ public function fetchRow(string $sql, array $params = []) * $db->fetchAll("SELECT * FROM users WHERE ip = ?", ['192.168.1.1']); * * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT * FROM users WHERE ip = :ip" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':ip' => '127.0.0.1') * * @return array[]|false @@ -405,9 +404,9 @@ public function fetchAll(string $sql, array $params = []) /** * Returns an array containing one column from the result set rows * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT id FROM users WHERE ip = :ip" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':ip' => '127.0.0.1') * * @return array|false @@ -431,10 +430,10 @@ public function fetchColumn(string $sql, array $params = []) * $db->fetchGroup("SELECT ip, COUNT(id) FROM users GROUP BY ip", []); * * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT ip, id FROM users" - * @param array $params params for query placeholders (optional) - * @param mixed $object + * @param array $params params for query placeholders (optional) + * @param mixed $object * * @return array|false * @throws DbException @@ -458,9 +457,9 @@ public function fetchGroup(string $sql, array $params = [], $object = null) * * Group by first column * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT ip, id FROM users" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * * @return array|false * @throws DbException @@ -479,9 +478,9 @@ public function fetchColumnGroup(string $sql, array $params = []) * * Group by first unique column * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT email, name, sex FROM users" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * * @return array|false * @throws DbException @@ -498,9 +497,9 @@ public function fetchUniqueGroup(string $sql, array $params = []) /** * Returns a key-value array * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT id, username FROM users WHERE ip = :ip" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':ip' => '127.0.0.1') * * @return array|false @@ -528,11 +527,11 @@ public function fetchPairs(string $sql, array $params = []) * $someClass = $db->fetchObject('SELECT * FROM some_table WHERE id = ?', [$id], $someClass); * * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT * FROM users WHERE name = :name AND pass = :pass" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':name' => 'John', ':pass' => '123456') - * @param mixed $object + * @param mixed $object * * @return mixed * @throws DbException @@ -558,11 +557,11 @@ public function fetchObject(string $sql, array $params = [], $object = 'stdClass /** * Returns an array of objects containing the result set * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT * FROM users WHERE name = :name AND pass = :pass" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':name' => 'John', ':pass' => '123456') - * @param mixed $object Class name or instance + * @param mixed $object Class name or instance * * @return array|false * @throws DbException @@ -587,12 +586,12 @@ public function fetchObjects(string $sql, array $params = [], $object = null) /** * Returns an array of linked objects containing the result set * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * "SELECT '__users', u.*, '__users_profile', up.* * FROM users u * LEFT JOIN users_profile up ON up.userId = u.id * WHERE u.name = :name" - * @param array $params params for query placeholders (optional) + * @param array $params params for query placeholders (optional) * array (':name' => 'John') * * @return array|false @@ -624,7 +623,7 @@ public function fetchRelations(string $sql, array $params = []) * }) * * - * @param callable $process callable structure - closure function or class with __invoke() method + * @param callable $process callable structure - closure function or class with __invoke() method * * @return mixed|bool * @throws DbException @@ -656,8 +655,8 @@ protected function ok(): void /** * Log queries by Application * - * @param string $query SQL query for logs - * @param array $context + * @param string $query SQL query for logs + * @param array $context * * @return void */ diff --git a/src/Db/Query/AbstractBuilder.php b/src/Db/Query/AbstractBuilder.php index d85876db..980088f5 100644 --- a/src/Db/Query/AbstractBuilder.php +++ b/src/Db/Query/AbstractBuilder.php @@ -98,7 +98,7 @@ public function getQuery(): string /** * Gets a (previously set) query parameter of the query being constructed * - * @param mixed $key The key (index or name) of the bound parameter + * @param mixed $key The key (index or name) of the bound parameter * * @return mixed The value of the bound parameter. */ @@ -120,9 +120,9 @@ public function getParam($key) * ->setParameter(':user_id', 1); * * - * @param string|int|null $key The parameter position or name - * @param mixed $value The parameter value - * @param integer $type PDO::PARAM_* + * @param string|int|null $key The parameter position or name + * @param mixed $value The parameter value + * @param int $type PDO::PARAM_* * * @return self */ @@ -164,8 +164,8 @@ public function getParams(): array * ]); * * - * @param array $params The query parameters to set - * @param array $types The query parameters types to set + * @param array $params The query parameters to set + * @param array $types The query parameters types to set * * @return self */ @@ -184,7 +184,7 @@ public function setParams(array $params, array $types = []): self * $builder->prepareCondition("WHERE id IN (?)", [..,..]); * * - * @param array $args + * @param array $args * * @return string */ @@ -204,9 +204,7 @@ protected function prepareCondition(array $args = []): string } unset($value); - $condition = preg_replace('/(\:REPLACE\:)/', '?', $condition); - - return $condition; + return preg_replace('/(:REPLACE:)/', '?', $condition); } /** diff --git a/src/Db/Query/CompositeBuilder.php b/src/Db/Query/CompositeBuilder.php index fb861782..df8e51f0 100644 --- a/src/Db/Query/CompositeBuilder.php +++ b/src/Db/Query/CompositeBuilder.php @@ -31,8 +31,8 @@ class CompositeBuilder implements \Countable /** * Constructor * - * @param array $parts parts of the composite expression - * @param string $type AND|OR + * @param array $parts parts of the composite expression + * @param string $type AND|OR */ public function __construct(array $parts = [], string $type = 'AND') { @@ -44,7 +44,7 @@ public function __construct(array $parts = [], string $type = 'AND') /** * Adds a set of expressions to composite expression * - * @param array $parts + * @param array $parts * * @return CompositeBuilder */ @@ -60,7 +60,7 @@ public function addParts($parts): CompositeBuilder /** * Adds an expression to composite expression * - * @param mixed $part + * @param mixed $part * * @return CompositeBuilder */ @@ -100,7 +100,7 @@ public function count(): int public function __toString() { if ($this->count() === 1) { - return (string) $this->parts[0]; + return (string)$this->parts[0]; } return '(' . implode(') ' . $this->type . ' (', $this->parts) . ')'; } diff --git a/src/Db/Query/Delete.php b/src/Db/Query/Delete.php index 2bd1cd8e..c4289bb0 100644 --- a/src/Db/Query/Delete.php +++ b/src/Db/Query/Delete.php @@ -54,7 +54,7 @@ public function getSql(): string * ->where('id = ?'); * * - * @param string $table The table whose rows are subject to the update + * @param string $table The table whose rows are subject to the update * * @return Delete instance */ diff --git a/src/Db/Query/Insert.php b/src/Db/Query/Insert.php index 9714fa4e..35494ea6 100644 --- a/src/Db/Query/Insert.php +++ b/src/Db/Query/Insert.php @@ -30,7 +30,7 @@ class Insert extends AbstractBuilder /** * {@inheritdoc} * - * @param null $sequence + * @param null $sequence * * @return integer|string|array */ @@ -68,7 +68,7 @@ public function getSql(): string * ->set('password', md5('password')); * * - * @param string $table The table into which the rows should be inserted + * @param string $table The table into which the rows should be inserted * * @return Insert instance */ diff --git a/src/Db/Query/Select.php b/src/Db/Query/Select.php index 8ea85c75..93e76ea9 100644 --- a/src/Db/Query/Select.php +++ b/src/Db/Query/Select.php @@ -48,7 +48,7 @@ class Select extends AbstractBuilder /** * {@inheritdoc} * - * @param integer|string|object $fetchType + * @param integer|string|object $fetchType * * @return integer|string|array */ @@ -72,7 +72,7 @@ public function execute($fetchType = null) /** * Setup fetch type, any of PDO, or any Class * - * @param string $fetchType + * @param string $fetchType * * @return Select instance */ @@ -109,7 +109,7 @@ public function getSql(): string * ->leftJoin('u', 'phone', 'p', 'u.id = p.user_id'); * * - * @param string[] $select the selection expressions + * @param string[] $select the selection expressions * * @return Select instance */ @@ -132,7 +132,7 @@ public function select(...$select): Select * ->leftJoin('u', 'phone', 'u.id = p.user_id'); * * - * @param string[] $select the selection expression + * @param string[] $select the selection expression * * @return Select instance */ @@ -145,7 +145,7 @@ public function addSelect(string ...$select): Select /** * Get current select query part * - * @return array + * @return string[] */ public function getSelect(): array { @@ -165,7 +165,7 @@ public function getSelect(): array * ->groupBy('u.id'); * * - * @param string[] $groupBy the grouping expression + * @param string[] $groupBy the grouping expression * * @return Select instance */ @@ -188,7 +188,7 @@ public function groupBy(string ...$groupBy): Select * ->addGroupBy('u.createdAt') * * - * @param string[] $groupBy the grouping expression + * @param string[] $groupBy the grouping expression * * @return Select instance */ @@ -202,7 +202,7 @@ public function addGroupBy(string ...$groupBy): Select * Specifies a restriction over the groups of the query. * Replaces any previous having restrictions, if any * - * @param string[] $conditions the query restriction predicates + * @param string[] $conditions the query restriction predicates * * @return Select */ @@ -216,7 +216,7 @@ public function having(...$conditions): Select * Adds a restriction over the groups of the query, forming a logical * conjunction with any existing having restrictions * - * @param string[] $conditions the query restriction predicates + * @param string[] $conditions the query restriction predicates * * @return Select */ @@ -239,7 +239,7 @@ public function andHaving(...$conditions): Select * Adds a restriction over the groups of the query, forming a logical * disjunction with any existing having restrictions * - * @param string[] $conditions the query restriction predicates + * @param string[] $conditions the query restriction predicates * * @return Select */ @@ -261,7 +261,7 @@ public function orHaving(...$conditions): Select /** * Setup offset like a page number, start from 1 * - * @param integer $page + * @param int $page * * @return Select * @throws DbException diff --git a/src/Db/Query/Traits/From.php b/src/Db/Query/Traits/From.php index c76867e7..37e796d3 100644 --- a/src/Db/Query/Traits/From.php +++ b/src/Db/Query/Traits/From.php @@ -65,8 +65,8 @@ trait From * ->from('users', 'u') * * - * @param string $from The table - * @param string $alias The alias of the table + * @param string $from The table + * @param string $alias The alias of the table * * @return $this */ @@ -94,10 +94,10 @@ public function from(string $from, string $alias): self * ->join('u', 'phone', 'p', 'p.is_primary = 1'); * * - * @param string $fromAlias The alias that points to a from clause - * @param string $join The table name to join - * @param string $alias The alias of the join table - * @param string $condition The condition for the join + * @param string $fromAlias The alias that points to a from clause + * @param string $join The table name to join + * @param string $alias The alias of the join table + * @param string $condition The condition for the join * * @return $this */ @@ -118,10 +118,10 @@ public function join(string $fromAlias, string $join, string $alias, string $con * ->innerJoin('u', 'phone', 'p', 'p.is_primary = 1'); * * - * @param string $fromAlias The alias that points to a from clause - * @param string $join The table name to join - * @param string $alias The alias of the join table - * @param string $condition The condition for the join + * @param string $fromAlias The alias that points to a from clause + * @param string $join The table name to join + * @param string $alias The alias of the join table + * @param string $condition The condition for the join * * @return $this */ @@ -142,10 +142,10 @@ public function innerJoin(string $fromAlias, string $join, string $alias, string * ->leftJoin('u', 'phone', 'p', 'p.is_primary = 1'); * * - * @param string $fromAlias The alias that points to a from clause - * @param string $join The table name to join - * @param string $alias The alias of the join table - * @param string $condition The condition for the join + * @param string $fromAlias The alias that points to a from clause + * @param string $join The table name to join + * @param string $alias The alias of the join table + * @param string $condition The condition for the join * * @return $this */ @@ -166,10 +166,10 @@ public function leftJoin(string $fromAlias, string $join, string $alias, string * ->rightJoin('u', 'phone', 'p', 'p.is_primary = 1'); * * - * @param string $fromAlias The alias that points to a from clause - * @param string $join The table name to join - * @param string $alias The alias of the join table - * @param string $condition The condition for the join + * @param string $fromAlias The alias that points to a from clause + * @param string $join The table name to join + * @param string $alias The alias of the join table + * @param string $condition The condition for the join * * @return $this */ @@ -181,11 +181,11 @@ public function rightJoin(string $fromAlias, string $join, string $alias, string /** * addJoin() * - * @param string $type The type of join - * @param string $fromAlias The alias that points to a from clause - * @param string $join The table name to join - * @param string $alias The alias of the join table - * @param string $condition The condition for the join + * @param string $type The type of join + * @param string $fromAlias The alias that points to a from clause + * @param string $join The table name to join + * @param string $alias The alias of the join table + * @param string $condition The condition for the join * * @return $this */ @@ -210,7 +210,7 @@ protected function addJoin( /** * setFromQueryPart * - * @param string $table + * @param string $table * * @return self */ @@ -241,7 +241,7 @@ protected function prepareFrom(): string /** * Generate SQL string for JOINs * - * @param string $fromAlias The alias of the table + * @param string $fromAlias The alias of the table * * @return string */ diff --git a/src/Db/Query/Traits/Limit.php b/src/Db/Query/Traits/Limit.php index 6e6e8c4d..67fb5ff6 100644 --- a/src/Db/Query/Traits/Limit.php +++ b/src/Db/Query/Traits/Limit.php @@ -37,8 +37,8 @@ trait Limit /** * Sets the maximum number of results to retrieve/update/delete * - * @param integer $limit The maximum number of results to retrieve - * @param integer $offset The offset of the query + * @param int $limit The maximum number of results to retrieve + * @param int $offset The offset of the query * * @return $this */ @@ -52,7 +52,7 @@ public function limit(int $limit, int $offset = 0): self /** * Setup limit for the query * - * @param integer $limit + * @param int $limit * * @return $this */ @@ -65,7 +65,7 @@ public function setLimit(int $limit): self /** * Setup offset for the query * - * @param integer $offset + * @param int $offset * * @return $this */ diff --git a/src/Db/Query/Traits/Order.php b/src/Db/Query/Traits/Order.php index 71e5545a..f28bf2c6 100644 --- a/src/Db/Query/Traits/Order.php +++ b/src/Db/Query/Traits/Order.php @@ -33,8 +33,8 @@ trait Order * Specifies an ordering for the query results * Replaces any previously specified orderings, if any * - * @param string $sort Sort expression - * @param string $order Sort direction (ASC or DESC) + * @param string $sort Sort expression + * @param string $order Sort direction (ASC or DESC) * * @return $this */ @@ -48,8 +48,8 @@ public function orderBy(string $sort, string $order = 'ASC'): self /** * Adds an ordering to the query results * - * @param string $sort Sort expression - * @param string $order Sort direction (ASC or DESC) + * @param string $sort Sort expression + * @param string $order Sort direction (ASC or DESC) * * @return $this */ diff --git a/src/Db/Query/Traits/Set.php b/src/Db/Query/Traits/Set.php index 0c2d920f..d98c98e7 100644 --- a/src/Db/Query/Traits/Set.php +++ b/src/Db/Query/Traits/Set.php @@ -50,9 +50,9 @@ trait Set * ->where('id = ?'); * * - * @param string $key The column to set - * @param string|integer $value The value, expression, placeholder, etc - * @param int $type The type of value on of PDO::PARAM_* params + * @param string $key The column to set + * @param string|integer $value The value, expression, placeholder, etc + * @param int $type The type of value on of PDO::PARAM_* params * * @return $this */ @@ -77,7 +77,7 @@ public function set(string $key, $value, $type = PDO::PARAM_STR): self * ->where('u.id = ?'); * * - * @param array $data + * @param array $data * * @return $this */ diff --git a/src/Db/Query/Traits/Where.php b/src/Db/Query/Traits/Where.php index 540b9208..7fb26527 100644 --- a/src/Db/Query/Traits/Where.php +++ b/src/Db/Query/Traits/Where.php @@ -45,7 +45,7 @@ trait Where * ; * * - * @param array $conditions optional the query restriction predicates + * @param array $conditions optional the query restriction predicates * * @return $this */ @@ -69,7 +69,7 @@ public function where(...$conditions): self * ->andWhere('u.is_active = ?', 1); * * - * @param string[] $conditions Optional the query restriction predicates + * @param string[] $conditions Optional the query restriction predicates * * @return $this */ @@ -102,7 +102,7 @@ public function andWhere(...$conditions): self * ->orWhere('u.id = ?', 2); * * - * @param string[] $conditions Optional the query restriction predicates + * @param string[] $conditions Optional the query restriction predicates * * @return $this */ diff --git a/src/Db/Query/Update.php b/src/Db/Query/Update.php index 549094d1..8ff80681 100644 --- a/src/Db/Query/Update.php +++ b/src/Db/Query/Update.php @@ -54,7 +54,7 @@ public function getSql(): string * ->where('id = ?'); * * - * @param string $table the table whose rows are subject to the update + * @param string $table the table whose rows are subject to the update * * @return Update instance */ diff --git a/src/Db/Relations.php b/src/Db/Relations.php index bb711d82..0fd280e2 100644 --- a/src/Db/Relations.php +++ b/src/Db/Relations.php @@ -141,7 +141,7 @@ public static function findRelation(Row $row, string $relation): array * * @param string $modelOne Table * @param string $modelTwo Target table - * @param array $keys Keys from first table + * @param array $keys Keys from first table * * @return array * @throws Exception\RelationNotFoundException diff --git a/src/Db/Row.php b/src/Db/Row.php index aff3d9f7..bc955eed 100644 --- a/src/Db/Row.php +++ b/src/Db/Row.php @@ -11,7 +11,7 @@ namespace Bluz\Db; -use Bluz\Common\Container; +use Bluz\Container; use Bluz\Db\Exception\DbException; use Bluz\Db\Exception\InvalidPrimaryKeyException; use Bluz\Db\Exception\TableNotFoundException; @@ -117,7 +117,7 @@ public function __debugInfo() /** * Validate input data * - * @param array $data + * @param array $data * * @return bool */ @@ -129,7 +129,7 @@ public function validate($data): bool /** * Assert input data * - * @param array $data + * @param array $data * * @return void */ diff --git a/src/Db/RowInterface.php b/src/Db/RowInterface.php index a17921b3..aa44853a 100644 --- a/src/Db/RowInterface.php +++ b/src/Db/RowInterface.php @@ -31,7 +31,7 @@ public function toArray(): array; /** * Sets all data in the row from an array * - * @param array $data + * @param array $data * * @return void */ diff --git a/src/Db/Table.php b/src/Db/Table.php index d30734a3..a1ba2c88 100755 --- a/src/Db/Table.php +++ b/src/Db/Table.php @@ -220,7 +220,7 @@ public static function filterColumns(array $data): array /** * Fetching rows by SQL query * - * @param string $sql SQL query with placeholders + * @param string $sql SQL query with placeholders * @param array $params Params for query placeholders * * @return RowInterface[] of rows results in FETCH_CLASS mode @@ -350,7 +350,7 @@ public static function findRowWhere(array $whereList): ?RowInterface /** * Prepare array for WHERE or SET statements * - * @param array $where + * @param array $where * * @return array */ diff --git a/src/Db/TableInterface.php b/src/Db/TableInterface.php index 88d56c14..c242fb01 100644 --- a/src/Db/TableInterface.php +++ b/src/Db/TableInterface.php @@ -48,7 +48,7 @@ public function getModel(): string; /** * Create Row instance * - * @param array $data + * @param array $data * * @return RowInterface */ @@ -79,7 +79,7 @@ public static function create(array $data = []): RowInterface; * Multiple rows by compound primary key * Table::find([123, 'abc'], [234, 'def'], [345, 'ghi']) * - * @param mixed ...$keys The value(s) of the primary keys. + * @param mixed ...$keys The value(s) of the primary keys. * * @return RowInterface[] */ @@ -100,7 +100,7 @@ public static function find(...$keys): array; * // WHERE (alias = 'foo' AND userId = 2) OR ('alias' = 'bar' AND userId = 4) * Table::findWhere(['alias'=>'foo', 'userId'=> 2], ['alias'=>'foo', 'userId'=>4]); * - * @param mixed ...$where + * @param mixed ...$where * * @return RowInterface[] */ @@ -109,7 +109,7 @@ public static function findWhere(...$where): array; /** * Find row by primary key * - * @param mixed $primaryKey + * @param mixed $primaryKey * * @return RowInterface */ @@ -118,7 +118,7 @@ public static function findRow($primaryKey): ?RowInterface; /** * Find row by where condition * - * @param array $whereList + * @param array $whereList * * @return RowInterface */ @@ -154,7 +154,7 @@ public static function select(): Query\Select; * Table::insert(['login' => 'Man', 'email' => 'man@example.com']) * * - * @param array $data Column-value pairs + * @param array $data Column-value pairs * * @return string|null Primary key or null */ @@ -167,8 +167,8 @@ public static function insert(array $data); * Table::update(['login' => 'Man', 'email' => 'man@domain.com'], ['id' => 42]) * * - * @param array $data Column-value pairs. - * @param array $where An array of SQL WHERE clause(s) + * @param array $data Column-value pairs. + * @param array $where An array of SQL WHERE clause(s) * * @return integer The number of rows updated */ @@ -181,7 +181,7 @@ public static function update(array $data, array $where): int; * Table::delete(['login' => 'Man']) * * - * @param array $where An array of SQL WHERE clause(s) + * @param array $where An array of SQL WHERE clause(s) * * @return integer The number of rows deleted */ diff --git a/src/Db/Traits/RowRelations.php b/src/Db/Traits/RowRelations.php index eb9f00a1..50217159 100644 --- a/src/Db/Traits/RowRelations.php +++ b/src/Db/Traits/RowRelations.php @@ -33,7 +33,7 @@ trait RowRelations /** * Set relation * - * @param Row $row + * @param Row $row * * @return void * @throws TableNotFoundException @@ -47,7 +47,7 @@ public function setRelation(Row $row): void /** * Get relation by model name * - * @param string $modelName + * @param string $modelName * * @return RowInterface * @throws RelationNotFoundException @@ -62,7 +62,7 @@ public function getRelation($modelName): ?RowInterface /** * Get relations by model name * - * @param string $modelName + * @param string $modelName * * @return RowInterface[] * @throws RelationNotFoundException diff --git a/src/Db/Traits/TableProperty.php b/src/Db/Traits/TableProperty.php index 5f024ae1..1df5ab55 100644 --- a/src/Db/Traits/TableProperty.php +++ b/src/Db/Traits/TableProperty.php @@ -23,14 +23,14 @@ trait TableProperty { /** - * @var TableInterface instance + * @var TableInterface|null instance */ - protected $table; + protected ?TableInterface $table = null; /** * Setup Table instance * - * @param TableInterface $table + * @param TableInterface $table * * @return void */ diff --git a/src/Db/Traits/TableRelations.php b/src/Db/Traits/TableRelations.php index 0e68b57d..650a2c26 100644 --- a/src/Db/Traits/TableRelations.php +++ b/src/Db/Traits/TableRelations.php @@ -24,9 +24,9 @@ trait TableRelations /** * Setup relation "one to one" or "one to many" * - * @param string $key - * @param string $model - * @param string $foreign + * @param string $key + * @param string $model + * @param string $foreign * * @return void */ @@ -39,8 +39,8 @@ public function linkTo($key, $model, $foreign): void * Setup relation "many to many" * [table1-key] [table1_key-table2-table3_key] [table3-key] * - * @param string $model - * @param string $link + * @param string $model + * @param string $link * * @return void */ diff --git a/src/EventManager/Event.php b/src/EventManager/Event.php index 6fbed6c2..82469da4 100644 --- a/src/EventManager/Event.php +++ b/src/EventManager/Event.php @@ -21,30 +21,28 @@ class Event /** * @var string event name */ - protected $name; + protected string $name; /** - * @var string|object the event target + * @var mixed the event target */ - protected $target; + protected mixed $target = null; /** - * @var array|object the event parameters + * @var array the event parameters */ - protected $params = []; + protected array $params = []; /** * Constructor * * Accept a target and its parameters. * - * @param string $name Event name - * @param string|object $target - * @param array|object $params - * - * @throws EventException + * @param string $name Event name + * @param mixed $target + * @param array|null $params */ - public function __construct(string $name, $target = null, $params = null) + public function __construct(string $name, mixed $target = null, array $params = null) { $this->setName($name); @@ -72,9 +70,9 @@ public function getName(): string * * This may be either an object, or the name of a static method. * - * @return string|object + * @return mixed */ - public function getTarget() + public function getTarget(): mixed { return $this->target; } @@ -82,28 +80,21 @@ public function getTarget() /** * Overwrites parameters * - * @param array|object $params + * @param array $params * * @return void - * @throws EventException */ - public function setParams($params): void + public function setParams(array $params): void { - if (!is_array($params) && !is_object($params)) { - throw new EventException( - 'Event parameters must be an array or object; received `' . gettype($params) . '`' - ); - } - $this->params = $params; } /** * Get all parameters * - * @return array|object + * @return array */ - public function getParams() + public function getParams(): array { return $this->params; } @@ -113,23 +104,14 @@ public function getParams() * * If the parameter does not exist, the $default value will be returned. * - * @param string|int $name - * @param mixed $default + * @param int|string $name + * @param mixed|null $default * * @return mixed */ - public function getParam($name, $default = null) + public function getParam(int|string $name, mixed $default = null): mixed { - if (is_array($this->params)) { - // Check in params that are arrays or implement array access - return $this->params[$name] ?? $default; - } elseif (is_object($this->params)) { - // Check in normal objects - return $this->params->{$name} ?? $default; - } else { - // Wrong type, return default value - return $default; - } + return $this->params[$name] ?? $default; } /** @@ -147,11 +129,11 @@ public function setName(string $name): void /** * Set the event target/context * - * @param null|string|object $target + * @param mixed $target * * @return void */ - public function setTarget($target): void + public function setTarget(mixed $target): void { $this->target = $target; } @@ -159,19 +141,13 @@ public function setTarget($target): void /** * Set an individual parameter to a value * - * @param string|int $name - * @param mixed $value + * @param int|string $name + * @param mixed $value * * @return void */ - public function setParam($name, $value): void + public function setParam(int|string $name, mixed $value): void { - if (is_array($this->params)) { - // Arrays or objects implementing array access - $this->params[$name] = $value; - } else { - // Objects - $this->params->{$name} = $value; - } + $this->params[$name] = $value; } } diff --git a/src/EventManager/EventManager.php b/src/EventManager/EventManager.php index 95f7160d..54456b1c 100644 --- a/src/EventManager/EventManager.php +++ b/src/EventManager/EventManager.php @@ -22,14 +22,14 @@ class EventManager /** * @var array list of listeners */ - protected $listeners = []; + protected array $listeners = []; /** * Attach callback to event * * @param string $eventName * @param callable $callback - * @param integer $priority + * @param int $priority * * @return void */ @@ -47,20 +47,19 @@ public function attach(string $eventName, callable $callback, int $priority = 1) /** * Trigger event * - * @param string|Event $event - * @param string|object $target - * @param array|object $params + * @param string|Event $event + * @param mixed $target + * @param array|null $params * - * @return string|object - * @throws EventException + * @return mixed */ - public function trigger($event, $target = null, $params = null) + public function trigger(string|Event $event, mixed $target = null, array $params = null): mixed { if (!$event instanceof Event) { $event = new Event($event, $target, $params); } - if (false !== strpos($event->getName(), ':')) { + if (str_contains($event->getName(), ':')) { $namespace = substr($event->getName(), 0, strpos($event->getName(), ':')); if (isset($this->listeners[$namespace])) { diff --git a/src/Grid/Data.php b/src/Grid/Data.php index d25d3f09..129ea707 100644 --- a/src/Grid/Data.php +++ b/src/Grid/Data.php @@ -27,7 +27,7 @@ class Data extends \ArrayIterator /** * Set total rows * - * @param integer $total + * @param int $total * * @return void */ diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index f4052606..6160f421 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -416,7 +416,7 @@ public function setParams($params): void /** * Return params prepared for url builder * - * @param array $rewrite + * @param array $rewrite * * @return array */ @@ -501,7 +501,7 @@ public function addAllowOrder(string $column): void /** * Set allow orders * - * @param string[] $orders + * @param string[] $orders * * @return void */ @@ -572,7 +572,7 @@ public function addOrder(string $column, string $order = self::ORDER_ASC): void /** * Add order rules * - * @param array $orders + * @param array $orders * * @return void * @throws GridException @@ -602,7 +602,7 @@ public function setOrder(string $column, string $order = self::ORDER_ASC): void /** * Set orders * - * @param array $orders + * @param array $orders * * @return void * @throws GridException @@ -642,7 +642,7 @@ public function addAllowFilter(string $column): void /** * Set allowed filters * - * @param string[] $filters + * @param string[] $filters * * @return void */ @@ -780,7 +780,7 @@ public function applyAlias(string $column): string /** * Set page * - * @param integer $page + * @param int $page * * @return void * @throws GridException @@ -806,7 +806,7 @@ public function getPage(): int /** * Set limit per page * - * @param integer $limit + * @param int $limit * * @return void * @throws GridException @@ -832,7 +832,7 @@ public function getLimit(): int /** * Set default limit * - * @param integer $limit + * @param int $limit * * @return void * @throws GridException diff --git a/src/Grid/Helper/Order.php b/src/Grid/Helper/Order.php index 95502b28..db33aa2a 100644 --- a/src/Grid/Helper/Order.php +++ b/src/Grid/Helper/Order.php @@ -16,7 +16,7 @@ return /** * @param string $column - * @param null $order + * @param null $order * @param string $defaultOrder * @param bool $reset * diff --git a/src/Grid/Source/AbstractSource.php b/src/Grid/Source/AbstractSource.php index 33988aa3..8df3f194 100644 --- a/src/Grid/Source/AbstractSource.php +++ b/src/Grid/Source/AbstractSource.php @@ -44,8 +44,8 @@ abstract class AbstractSource /** * Process source * - * @param int $page - * @param int $limit + * @param int $page + * @param int $limit * @param array $filters * @param array $orders * @@ -56,7 +56,7 @@ abstract public function process(int $page, int $limit, array $filters = [], arr /** * Setup source adapter * - * @param mixed $source + * @param mixed $source * * @return void */ diff --git a/src/Grid/Source/ArraySource.php b/src/Grid/Source/ArraySource.php index 668281af..42231aa4 100644 --- a/src/Grid/Source/ArraySource.php +++ b/src/Grid/Source/ArraySource.php @@ -27,7 +27,7 @@ class ArraySource extends AbstractSource /** * Set array source * - * @param array $source + * @param array $source * * @return void * @throws Grid\GridException @@ -67,7 +67,7 @@ public function process(int $page, int $limit, array $filters = [], array $order /** * Apply filters to array * - * @param array $settings + * @param array $settings * * @return void * @throws Grid\GridException @@ -129,7 +129,7 @@ function ($row) use ($settings) { /** * Apply order to array * - * @param array $settings + * @param array $settings * * @return void * @throws Grid\GridException diff --git a/src/Grid/Source/SelectSource.php b/src/Grid/Source/SelectSource.php index 6840697d..848eb1da 100644 --- a/src/Grid/Source/SelectSource.php +++ b/src/Grid/Source/SelectSource.php @@ -29,10 +29,10 @@ class SelectSource extends AbstractSource /** * Set Select source * - * @param Db\Query\Select $source + * @param Db\Query\Select $source * - * @throws Grid\GridException * @return void + * @throws Grid\GridException */ public function setSource($source): void { @@ -98,7 +98,7 @@ function () use (&$data, &$total, $totalSql) { /** * Apply filters to Select * - * @param array $settings + * @param array $settings * * @return void * @throws Grid\GridException @@ -118,7 +118,7 @@ private function applyFilters(array $settings): void /** * Apply order to Select * - * @param array $settings + * @param array $settings * * @return void * @throws Grid\GridException diff --git a/src/Grid/Source/SqlSource.php b/src/Grid/Source/SqlSource.php index 3b4133eb..12d3a31d 100644 --- a/src/Grid/Source/SqlSource.php +++ b/src/Grid/Source/SqlSource.php @@ -30,7 +30,7 @@ class SqlSource extends AbstractSource /** * Set SQL source * - * @param string $source + * @param string $source * * @return void * @throws GridException @@ -96,7 +96,7 @@ function () use (&$data, &$total, $dataSql, $totalSql) { /** * Apply filters to SQL query * - * @param array[] $settings + * @param array[] $settings * * @return array */ @@ -119,7 +119,7 @@ private function applyFilters(array $settings): array /** * Apply order to SQL query * - * @param array $settings + * @param array $settings * * @return array */ diff --git a/src/Http/CacheControl.php b/src/Http/CacheControl.php index 581a7bbf..f3bd7730 100644 --- a/src/Http/CacheControl.php +++ b/src/Http/CacheControl.php @@ -11,7 +11,7 @@ namespace Bluz\Http; -use Bluz\Common\Container\Container; +use Bluz\Container\Container; use Bluz\Response\Response; use DateTime; use DateTimeZone; @@ -28,7 +28,6 @@ * - Age * * @package Bluz\Http - * @author Anton Shevchuk * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 */ @@ -39,7 +38,7 @@ class CacheControl /** * @var Response instance */ - protected $response; + protected Response $response; /** * Create instance @@ -110,7 +109,7 @@ public function setPublic(): void * First, it checks for a s-maxage directive, then a max-age directive, and then it falls * back on an expires header. It returns null when no maximum age can be established. * - * @return integer|null Number of seconds + * @return int|null Number of seconds */ public function getMaxAge(): ?int { @@ -124,7 +123,7 @@ public function getMaxAge(): ?int if ($expires = $this->getExpires()) { $expires = DateTime::createFromFormat(DATE_RFC2822, $expires); - return (int) $expires->format('U') - date('U'); + return (int)$expires->format('U') - date('U'); } return null; @@ -135,7 +134,7 @@ public function getMaxAge(): ?int * * This methods sets the Cache-Control max-age directive. * - * @param integer $value Number of seconds + * @param int $value Number of seconds * * @return void */ @@ -150,7 +149,7 @@ public function setMaxAge(int $value): void * * This methods sets the Cache-Control s-maxage directive. * - * @param integer $value Number of seconds + * @param int $value Number of seconds * * @return void */ @@ -168,14 +167,11 @@ public function setSharedMaxAge(int $value): void * When the responses TTL is <= 0, the response may not be served from cache without first * revalidating with the origin. * - * @return integer|null The TTL in seconds + * @return int|null The TTL in seconds */ public function getTtl(): ?int { - if ($maxAge = $this->getMaxAge()) { - return $maxAge - $this->getAge(); - } - return null; + return ($maxAge = $this->getMaxAge()) ? $maxAge - $this->getAge() : null; } /** @@ -183,7 +179,7 @@ public function getTtl(): ?int * * This method adjusts the Cache-Control/s-maxage directive. * - * @param integer $seconds Number of seconds + * @param int $seconds Number of seconds * * @return void */ @@ -197,7 +193,7 @@ public function setTtl(int $seconds): void * * This method adjusts the Cache-Control/max-age directive. * - * @param integer $seconds Number of seconds + * @param int $seconds Number of seconds * * @return void */ @@ -233,7 +229,7 @@ public function setEtag(string $etag, bool $weak = false): void /** * Returns the age of the response * - * @return integer The age of the response in seconds + * @return int The age of the response in seconds */ public function getAge(): int { @@ -246,7 +242,7 @@ public function getAge(): int /** * Set the age of the response * - * @param integer $age + * @param int $age * * @return void */ @@ -273,13 +269,9 @@ public function getExpires(): string * @return void * @throws Exception */ - public function setExpires($date): void + public function setExpires(DateTime|string $date): void { - if ($date instanceof DateTime) { - $date = clone $date; - } else { - $date = new DateTime($date); - } + $date = $date instanceof DateTime ? clone $date : new DateTime($date); $date->setTimezone(new DateTimeZone('UTC')); $this->response->setHeader('Expires', $date->format('D, d M Y H:i:s') . ' GMT'); @@ -298,18 +290,14 @@ public function getLastModified(): string /** * Sets the Last-Modified HTTP header with a DateTime instance or string * - * @param DateTime|string $date A \DateTime instance or date as string + * @param DateTime|string $date A \DateTime instance or date as string * * @return void * @throws Exception */ - public function setLastModified($date): void + public function setLastModified(DateTime|string $date): void { - if ($date instanceof DateTime) { - $date = clone $date; - } else { - $date = new DateTime($date); - } + $date = $date instanceof DateTime ? clone $date : new DateTime($date); $date->setTimezone(new DateTimeZone('UTC')); $this->response->setHeader('Last-Modified', $date->format('D, d M Y H:i:s') . ' GMT'); diff --git a/src/Http/Exception/BadRequestException.php b/src/Http/Exception/BadRequestException.php index d71cfed6..5ce77ae2 100644 --- a/src/Http/Exception/BadRequestException.php +++ b/src/Http/Exception/BadRequestException.php @@ -17,12 +17,8 @@ * BadRequest Exception * * @package Bluz\Http\Exception - * @author Anton Shevchuk */ class BadRequestException extends HttpException { - /** - * @var integer HTTP Code - */ - protected $code = StatusCode::BAD_REQUEST; + protected StatusCode $statusCode = StatusCode::BAD_REQUEST; } diff --git a/src/Http/Exception/ForbiddenException.php b/src/Http/Exception/ForbiddenException.php index e3774e98..9e63ade8 100644 --- a/src/Http/Exception/ForbiddenException.php +++ b/src/Http/Exception/ForbiddenException.php @@ -21,8 +21,5 @@ */ class ForbiddenException extends HttpException { - /** - * @var integer HTTP Code - */ - protected $code = StatusCode::FORBIDDEN; + protected StatusCode $statusCode = StatusCode::FORBIDDEN; } diff --git a/src/Http/Exception/HttpException.php b/src/Http/Exception/HttpException.php index ba9d0c11..a0b11f24 100644 --- a/src/Http/Exception/HttpException.php +++ b/src/Http/Exception/HttpException.php @@ -22,13 +22,37 @@ */ class HttpException extends CommonException { + /** + * @var StatusCode Used as default HTTP code for exceptions + */ + protected StatusCode $statusCode = StatusCode::INTERNAL_SERVER_ERROR; + + public function __construct(string $message = "", int $code = 0, ?\Throwable $previous = null) + { + parent::__construct( + $message ?: $this->statusCode->message(), + $code ?: $this->statusCode->value, + $previous + ); + } + + /** + * Return HTTP Status Message + * + * @return StatusCode + */ + public function getStatusCode(): StatusCode + { + return $this->statusCode; + } + /** * Return HTTP Status Message * * @return string */ - public function getStatus(): string + public function getStatusCodeMessage(): string { - return StatusCode::$statusTexts[$this->code]; + return $this->statusCode->message(); } } diff --git a/src/Http/Exception/NotAcceptableException.php b/src/Http/Exception/NotAcceptableException.php index 006c7472..3c7e8ad5 100644 --- a/src/Http/Exception/NotAcceptableException.php +++ b/src/Http/Exception/NotAcceptableException.php @@ -21,8 +21,5 @@ */ class NotAcceptableException extends HttpException { - /** - * @var integer HTTP Code - */ - protected $code = StatusCode::NOT_ACCEPTABLE; + protected StatusCode $statusCode = StatusCode::NOT_ACCEPTABLE; } diff --git a/src/Http/Exception/NotAllowedException.php b/src/Http/Exception/NotAllowedException.php index 3c834cd3..fb54339a 100644 --- a/src/Http/Exception/NotAllowedException.php +++ b/src/Http/Exception/NotAllowedException.php @@ -21,8 +21,5 @@ */ class NotAllowedException extends HttpException { - /** - * @var integer HTTP Code - */ - protected $code = StatusCode::METHOD_NOT_ALLOWED; + protected StatusCode $statusCode = StatusCode::METHOD_NOT_ALLOWED; } diff --git a/src/Http/Exception/NotFoundException.php b/src/Http/Exception/NotFoundException.php index 64d14332..4cae47b5 100644 --- a/src/Http/Exception/NotFoundException.php +++ b/src/Http/Exception/NotFoundException.php @@ -21,8 +21,5 @@ */ class NotFoundException extends HttpException { - /** - * @var integer HTTP Code - */ - protected $code = StatusCode::NOT_FOUND; + protected StatusCode $statusCode = StatusCode::NOT_FOUND; } diff --git a/src/Http/Exception/NotImplementedException.php b/src/Http/Exception/NotImplementedException.php index 2fed7074..231040d0 100644 --- a/src/Http/Exception/NotImplementedException.php +++ b/src/Http/Exception/NotImplementedException.php @@ -21,8 +21,5 @@ */ class NotImplementedException extends HttpException { - /** - * @var integer HTTP code - */ - protected $code = StatusCode::NOT_IMPLEMENTED; + protected StatusCode $statusCode = StatusCode::NOT_IMPLEMENTED; } diff --git a/src/Http/Exception/RedirectException.php b/src/Http/Exception/RedirectException.php index 9af95753..205be01c 100644 --- a/src/Http/Exception/RedirectException.php +++ b/src/Http/Exception/RedirectException.php @@ -27,22 +27,20 @@ class RedirectException extends HttpException * - 301 Moved Permanently * - 302 Moved Temporarily / Found * - 307 Temporary Redirect - * - * @var integer */ - protected $code = StatusCode::FOUND; + protected StatusCode $statusCode = StatusCode::FOUND; /** * @var string */ - protected $url; + protected string $url; /** * Set Url to Redirect * * @param string $url */ - public function setUrl($url): void + public function setUrl(string $url): void { $this->url = $url; } diff --git a/src/Http/Exception/UnauthorizedException.php b/src/Http/Exception/UnauthorizedException.php index 391d817c..18aff8b4 100644 --- a/src/Http/Exception/UnauthorizedException.php +++ b/src/Http/Exception/UnauthorizedException.php @@ -21,8 +21,5 @@ */ class UnauthorizedException extends HttpException { - /** - * @var integer HTTP code - */ - protected $code = StatusCode::UNAUTHORIZED; + protected StatusCode $statusCode = StatusCode::UNAUTHORIZED; } diff --git a/src/Http/RequestMethod.php b/src/Http/RequestMethod.php index 5a792e49..1950f32f 100644 --- a/src/Http/RequestMethod.php +++ b/src/Http/RequestMethod.php @@ -12,23 +12,20 @@ namespace Bluz\Http; /** - * RequestMethod + * Request HTTP methods * * @package Bluz\Http - * @author dark */ -class RequestMethod +enum RequestMethod : string { - /** - * @const string HTTP methods - */ - public const OPTIONS = 'OPTIONS'; - public const GET = 'GET'; - public const HEAD = 'HEAD'; - public const PATCH = 'PATCH'; - public const POST = 'POST'; - public const PUT = 'PUT'; - public const DELETE = 'DELETE'; - public const TRACE = 'TRACE'; - public const CONNECT = 'CONNECT'; + case CONNECT = 'CONNECT'; + case DELETE = 'DELETE'; + case GET = 'GET'; + case HEAD = 'HEAD'; + case OPTIONS = 'OPTIONS'; + case PATCH = 'PATCH'; + case POST = 'POST'; + case PURGE = 'PURGE'; + case PUT = 'PUT'; + case TRACE = 'TRACE'; } diff --git a/src/Http/StatusCode.php b/src/Http/StatusCode.php index bf411b76..fbfa7498 100644 --- a/src/Http/StatusCode.php +++ b/src/Http/StatusCode.php @@ -12,145 +12,148 @@ namespace Bluz\Http; /** - * HTTP Status Codes with translation table + * Hypertext Transfer Protocol (HTTP) Status Code Registry * * @package Bluz\Http - * @author Anton Shevchuk */ -class StatusCode +enum StatusCode: int { - public const CONTINUE = 100; - public const SWITCHING_PROTOCOLS = 101; - public const PROCESSING = 102; // RFC2518 - public const OK = 200; - public const CREATED = 201; - public const ACCEPTED = 202; - public const NON_AUTHORITATIVE_INFORMATION = 203; - public const NO_CONTENT = 204; - public const RESET_CONTENT = 205; - public const PARTIAL_CONTENT = 206; - public const MULTI_STATUS = 207; // RFC4918 - public const ALREADY_REPORTED = 208; // RFC5842 - public const IM_USED = 226; // RFC3229 - public const MULTIPLE_CHOICES = 300; - public const MOVED_PERMANENTLY = 301; - public const FOUND = 302; - public const SEE_OTHER = 303; - public const NOT_MODIFIED = 304; - public const USE_PROXY = 305; - public const RESERVED = 306; - public const TEMPORARY_REDIRECT = 307; - public const PERMANENTLY_REDIRECT = 308; // RFC7238 - public const BAD_REQUEST = 400; - public const UNAUTHORIZED = 401; - public const PAYMENT_REQUIRED = 402; - public const FORBIDDEN = 403; - public const NOT_FOUND = 404; - public const METHOD_NOT_ALLOWED = 405; - public const NOT_ACCEPTABLE = 406; - public const PROXY_AUTHENTICATION_REQUIRED = 407; - public const REQUEST_TIMEOUT = 408; - public const CONFLICT = 409; - public const GONE = 410; - public const LENGTH_REQUIRED = 411; - public const PRECONDITION_FAILED = 412; - public const REQUEST_ENTITY_TOO_LARGE = 413; - public const REQUEST_URI_TOO_LONG = 414; - public const UNSUPPORTED_MEDIA_TYPE = 415; - public const REQUESTED_RANGE_NOT_SATISFIABLE = 416; - public const EXPECTATION_FAILED = 417; - public const I_AM_A_TEAPOT = 418; // RFC2324 - public const MISDIRECTED_REQUEST = 421; // RFC7540 - public const UNPROCESSABLE_ENTITY = 422; // RFC4918 - public const LOCKED = 423; // RFC4918 - public const FAILED_DEPENDENCY = 424; // RFC4918 - public const RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; // RFC2817 - public const UPGRADE_REQUIRED = 426; // RFC2817 - public const PRECONDITION_REQUIRED = 428; // RFC6585 - public const TOO_MANY_REQUESTS = 429; // RFC6585 - public const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 - public const UNAVAILABLE_FOR_LEGAL_REASONS = 451; - public const INTERNAL_SERVER_ERROR = 500; - public const NOT_IMPLEMENTED = 501; - public const BAD_GATEWAY = 502; - public const SERVICE_UNAVAILABLE = 503; - public const GATEWAY_TIMEOUT = 504; - public const VERSION_NOT_SUPPORTED = 505; - public const VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 - public const INSUFFICIENT_STORAGE = 507; // RFC4918 - public const LOOP_DETECTED = 508; // RFC5842 - public const NOT_EXTENDED = 510; // RFC2774 - public const NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 + case CONTINUE = 100; + case SWITCHING_PROTOCOLS = 101; + case PROCESSING = 102; // RFC2518 + case EARLY_HINTS = 103; // RFC8297 + case OK = 200; + case CREATED = 201; + case ACCEPTED = 202; + case NON_AUTHORITATIVE_INFORMATION = 203; + case NO_CONTENT = 204; + case RESET_CONTENT = 205; + case PARTIAL_CONTENT = 206; + case MULTI_STATUS = 207; // RFC4918 + case ALREADY_REPORTED = 208; // RFC5842 + case IM_USED = 226; // RFC3229 + case MULTIPLE_CHOICES = 300; + case MOVED_PERMANENTLY = 301; + case FOUND = 302; + case SEE_OTHER = 303; + case NOT_MODIFIED = 304; + case USE_PROXY = 305; + case SWITCH_PROXY = 306; + case TEMPORARY_REDIRECT = 307; + case PERMANENTLY_REDIRECT = 308; // RFC7238 + case BAD_REQUEST = 400; + case UNAUTHORIZED = 401; + case PAYMENT_REQUIRED = 402; + case FORBIDDEN = 403; + case NOT_FOUND = 404; + case METHOD_NOT_ALLOWED = 405; + case NOT_ACCEPTABLE = 406; + case PROXY_AUTHENTICATION_REQUIRED = 407; + case REQUEST_TIMEOUT = 408; + case CONFLICT = 409; + case GONE = 410; + case LENGTH_REQUIRED = 411; + case PRECONDITION_FAILED = 412; + case REQUEST_ENTITY_TOO_LARGE = 413; + case REQUEST_URI_TOO_LONG = 414; + case UNSUPPORTED_MEDIA_TYPE = 415; + case REQUESTED_RANGE_NOT_SATISFIABLE = 416; + case EXPECTATION_FAILED = 417; + case I_AM_A_TEAPOT = 418; // RFC2324 + case MISDIRECTED_REQUEST = 421; // RFC7540 + case UNPROCESSABLE_ENTITY = 422; // RFC4918 + case LOCKED = 423; // RFC4918 + case FAILED_DEPENDENCY = 424; // RFC4918 + case TOO_EARLY = 425; // RFC8740 + case UPGRADE_REQUIRED = 426; // RFC2817 + case PRECONDITION_REQUIRED = 428; // RFC6585 + case TOO_MANY_REQUESTS = 429; // RFC6585 + case REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 + case UNAVAILABLE_FOR_LEGAL_REASONS = 451; // RFC7725 + case INTERNAL_SERVER_ERROR = 500; + case NOT_IMPLEMENTED = 501; + case BAD_GATEWAY = 502; + case SERVICE_UNAVAILABLE = 503; + case GATEWAY_TIMEOUT = 504; + case VERSION_NOT_SUPPORTED = 505; + case VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 + case INSUFFICIENT_STORAGE = 507; // RFC4918 + case LOOP_DETECTED = 508; // RFC5842 + case NOT_EXTENDED = 510; // RFC2774 + case NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 /** * Status codes translation table * * The list of codes is complete according to the * {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol Status Code Registry} - * - * @var array */ - public static $statusTexts = [ - 100 => 'Continue', - 101 => 'Switching Protocols', - 102 => 'Processing', // RFC2518 - 200 => 'OK', - 201 => 'Created', - 202 => 'Accepted', - 203 => 'Non-Authoritative Information', - 204 => 'No Content', - 205 => 'Reset Content', - 206 => 'Partial Content', - 207 => 'Multi-Status', // RFC4918 - 208 => 'Already Reported', // RFC5842 - 226 => 'IM Used', // RFC3229 - 300 => 'Multiple Choices', - 301 => 'Moved Permanently', - 302 => 'Found', - 303 => 'See Other', - 304 => 'Not Modified', - 305 => 'Use Proxy', - 307 => 'Temporary Redirect', - 308 => 'Permanent Redirect', // RFC7238 - 400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Payload Too Large', - 414 => 'URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Range Not Satisfiable', - 417 => 'Expectation Failed', - 418 => 'I\'m a teapot', // RFC2324 - 421 => 'Misdirected Request', // RFC7540 - 422 => 'Unprocessable Entity', // RFC4918 - 423 => 'Locked', // RFC4918 - 424 => 'Failed Dependency', // RFC4918 - 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 - 426 => 'Upgrade Required', // RFC2817 - 428 => 'Precondition Required', // RFC6585 - 429 => 'Too Many Requests', // RFC6585 - 431 => 'Request Header Fields Too Large', // RFC6585 - 451 => 'Unavailable For Legal Reasons', // RFC7725 - 500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported', - 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 - 507 => 'Insufficient Storage', // RFC4918 - 508 => 'Loop Detected', // RFC5842 - 510 => 'Not Extended', // RFC2774 - 511 => 'Network Authentication Required', // RFC6585 - ]; + public function message(): string + { + return match ($this) { + self::CONTINUE => _('Continue'), + self::SWITCHING_PROTOCOLS => _('Switching Protocols'), + self::PROCESSING => _('Processing'), + self::EARLY_HINTS => _('Early Hints'), + self::OK => _('OK'), + self::CREATED => _('Created'), + self::ACCEPTED => _('Accepted'), + self::NON_AUTHORITATIVE_INFORMATION => _('Non-Authoritative Information'), + self::NO_CONTENT => _('No Content'), + self::RESET_CONTENT => _('Reset Content'), + self::PARTIAL_CONTENT => _('Partial Content'), + self::MULTI_STATUS => _('Multi-Status'), + self::ALREADY_REPORTED => _('Already Reported'), + self::IM_USED => _('IM Used'), + self::MULTIPLE_CHOICES => _('Multiple Choices'), + self::MOVED_PERMANENTLY => _('Moved Permanently'), + self::FOUND => _('Found'), + self::SEE_OTHER => _('See Other'), + self::NOT_MODIFIED => _('Not Modified'), + self::USE_PROXY => _('Use Proxy'), + self::SWITCH_PROXY => _('Switch Proxy is a reserved and unused status code'), + self::TEMPORARY_REDIRECT => _('Temporary Redirect'), + self::PERMANENTLY_REDIRECT => _('Permanent Redirect'), + self::BAD_REQUEST => _('Bad Request'), + self::UNAUTHORIZED => _('Unauthorized'), + self::PAYMENT_REQUIRED => _('Payment Required'), + self::FORBIDDEN => _('Forbidden'), + self::NOT_FOUND => _('Not Found'), + self::METHOD_NOT_ALLOWED => _('Method Not Allowed'), + self::NOT_ACCEPTABLE => _('Not Acceptable'), + self::PROXY_AUTHENTICATION_REQUIRED => _('Proxy Authentication Required'), + self::REQUEST_TIMEOUT => _('Request Timeout'), + self::CONFLICT => _('Conflict'), + self::GONE => _('Gone'), + self::LENGTH_REQUIRED => _('Length Required'), + self::PRECONDITION_FAILED => _('Precondition Failed'), + self::REQUEST_ENTITY_TOO_LARGE => _('Payload Too Large'), + self::REQUEST_URI_TOO_LONG => _('URI Too Long'), + self::UNSUPPORTED_MEDIA_TYPE => _('Unsupported Media Type'), + self::REQUESTED_RANGE_NOT_SATISFIABLE => _('Range Not Satisfiable'), + self::EXPECTATION_FAILED => _('Expectation Failed'), + self::I_AM_A_TEAPOT => _('I\'m a teapot'), + self::MISDIRECTED_REQUEST => _('Misdirected Request'), + self::UNPROCESSABLE_ENTITY => _('Unprocessable Entity'), + self::LOCKED => _('Locked'), + self::FAILED_DEPENDENCY => _('Failed Dependency'), + self::TOO_EARLY => _('Too Early'), + self::UPGRADE_REQUIRED => _('Upgrade Required'), + self::PRECONDITION_REQUIRED => _('Precondition Required'), + self::TOO_MANY_REQUESTS => _('Too Many Requests'), + self::REQUEST_HEADER_FIELDS_TOO_LARGE => _('Request Header Fields Too Large'), + self::UNAVAILABLE_FOR_LEGAL_REASONS => _('Unavailable For Legal Reasons'), + self::INTERNAL_SERVER_ERROR => _('Internal Server Error'), + self::NOT_IMPLEMENTED => _('Not Implemented'), + self::BAD_GATEWAY => _('Bad Gateway'), + self::SERVICE_UNAVAILABLE => _('Service Unavailable'), + self::GATEWAY_TIMEOUT => _('Gateway Timeout'), + self::VERSION_NOT_SUPPORTED => _('HTTP Version Not Supported'), + self::VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL => _('Variant Also Negotiates (Experimental)'), + self::INSUFFICIENT_STORAGE => _('Insufficient Storage'), + self::LOOP_DETECTED => _('Loop Detected'), + self::NOT_EXTENDED => _('Not Extended'), + self::NETWORK_AUTHENTICATION_REQUIRED => _('Network Authentication Required'), + }; + } } diff --git a/src/Layout/Helper/BreadCrumbs.php b/src/Layout/Helper/BreadCrumbs.php index be526f66..93b9f3bd 100644 --- a/src/Layout/Helper/BreadCrumbs.php +++ b/src/Layout/Helper/BreadCrumbs.php @@ -16,7 +16,7 @@ /** * Set or Get Breadcrumbs * - * @param array $data + * @param array $data * * @return array|null */ diff --git a/src/Layout/Helper/HeadScript.php b/src/Layout/Helper/HeadScript.php index 9d900f53..1bd25f0e 100644 --- a/src/Layout/Helper/HeadScript.php +++ b/src/Layout/Helper/HeadScript.php @@ -18,7 +18,7 @@ * Set or generate ` - * - * But will *not* be true for strings like: - * - * - `Home` - * - `
Home` - * - `` - * - * For checking the raw source code, use `seeInSource()`. - * - * @param string $text - * @param array|string $selector optional - * @see \Codeception\Lib\InnerBrowser::see() - */ - public function see($text, $selector = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('see', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current page contains the given string (case insensitive). - * - * You can specify a specific HTML element (via CSS or XPath) as the second - * parameter to only search within that element. - * - * ``` php - * see('Logout'); // I can suppose user is logged in - * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page - * $I->see('Sign Up', '//body/h1'); // with XPath - * $I->see('Sign Up', ['css' => 'body h1']); // with strict CSS locator - * ``` - * - * Note that the search is done after stripping all HTML tags from the body, - * so `$I->see('strong')` will return true for strings like: - * - * - `

I am Stronger than thou

` - * - `` - * - * But will *not* be true for strings like: - * - * - `Home` - * - `
Home` - * - `` - * - * For checking the raw source code, use `seeInSource()`. - * - * @param string $text - * @param array|string $selector optional - * @see \Codeception\Lib\InnerBrowser::see() - */ - public function canSee($text, $selector = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('see', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current page doesn't contain the text specified (case insensitive). - * Give a locator as the second parameter to match a specific region. - * - * ```php - * dontSee('Login'); // I can suppose user is already logged in - * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page - * $I->dontSee('Sign Up','//body/h1'); // with XPath - * $I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator - * ``` - * - * Note that the search is done after stripping all HTML tags from the body, - * so `$I->dontSee('strong')` will fail on strings like: - * - * - `

I am Stronger than thou

` - * - `` - * - * But will ignore strings like: - * - * - `Home` - * - `
Home` - * - `` - * - * For checking the raw source code, use `seeInSource()`. - * - * @param string $text - * @param array|string $selector optional - * @see \Codeception\Lib\InnerBrowser::dontSee() - */ - public function dontSee($text, $selector = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSee', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current page doesn't contain the text specified (case insensitive). - * Give a locator as the second parameter to match a specific region. - * - * ```php - * dontSee('Login'); // I can suppose user is already logged in - * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page - * $I->dontSee('Sign Up','//body/h1'); // with XPath - * $I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator - * ``` - * - * Note that the search is done after stripping all HTML tags from the body, - * so `$I->dontSee('strong')` will fail on strings like: - * - * - `

I am Stronger than thou

` - * - `` - * - * But will ignore strings like: - * - * - `Home` - * - `
Home` - * - `` - * - * For checking the raw source code, use `seeInSource()`. - * - * @param string $text - * @param array|string $selector optional - * @see \Codeception\Lib\InnerBrowser::dontSee() - */ - public function cantSee($text, $selector = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSee', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current page contains the given string in its - * raw source code. - * - * ``` php - * seeInSource('

Green eggs & ham

'); - * ``` - * - * @param $raw - * @see \Codeception\Lib\InnerBrowser::seeInSource() - */ - public function seeInSource($raw) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInSource', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current page contains the given string in its - * raw source code. - * - * ``` php - * seeInSource('

Green eggs & ham

'); - * ``` - * - * @param $raw - * @see \Codeception\Lib\InnerBrowser::seeInSource() - */ - public function canSeeInSource($raw) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeInSource', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current page contains the given string in its - * raw source code. - * - * ```php - * dontSeeInSource('

Green eggs & ham

'); - * ``` - * - * @param $raw - * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() - */ - public function dontSeeInSource($raw) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInSource', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current page contains the given string in its - * raw source code. - * - * ```php - * dontSeeInSource('

Green eggs & ham

'); - * ``` - * - * @param $raw - * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() - */ - public function cantSeeInSource($raw) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeInSource', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there's a link with the specified text. - * Give a full URL as the second parameter to match links with that exact URL. - * - * ``` php - * seeLink('Logout'); // matches Logout - * $I->seeLink('Logout','/logout'); // matches Logout - * ?> - * ``` - * - * @param string $text - * @param string $url optional - * @see \Codeception\Lib\InnerBrowser::seeLink() - */ - public function seeLink($text, $url = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeLink', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that there's a link with the specified text. - * Give a full URL as the second parameter to match links with that exact URL. - * - * ``` php - * seeLink('Logout'); // matches Logout - * $I->seeLink('Logout','/logout'); // matches Logout - * ?> - * ``` - * - * @param string $text - * @param string $url optional - * @see \Codeception\Lib\InnerBrowser::seeLink() - */ - public function canSeeLink($text, $url = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeLink', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page doesn't contain a link with the given string. - * If the second parameter is given, only links with a matching "href" attribute will be checked. - * - * ``` php - * dontSeeLink('Logout'); // I suppose user is not logged in - * $I->dontSeeLink('Checkout now', '/store/cart.php'); - * ?> - * ``` - * - * @param string $text - * @param string $url optional - * @see \Codeception\Lib\InnerBrowser::dontSeeLink() - */ - public function dontSeeLink($text, $url = "") - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeLink', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the page doesn't contain a link with the given string. - * If the second parameter is given, only links with a matching "href" attribute will be checked. - * - * ``` php - * dontSeeLink('Logout'); // I suppose user is not logged in - * $I->dontSeeLink('Checkout now', '/store/cart.php'); - * ?> - * ``` - * - * @param string $text - * @param string $url optional - * @see \Codeception\Lib\InnerBrowser::dontSeeLink() - */ - public function cantSeeLink($text, $url = "") - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeLink', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that current URI contains the given string. - * - * ``` php - * seeInCurrentUrl('home'); - * // to match: /users/1 - * $I->seeInCurrentUrl('/users/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() - */ - public function seeInCurrentUrl($uri) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInCurrentUrl', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that current URI contains the given string. - * - * ``` php - * seeInCurrentUrl('home'); - * // to match: /users/1 - * $I->seeInCurrentUrl('/users/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() - */ - public function canSeeInCurrentUrl($uri) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeInCurrentUrl', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URI doesn't contain the given string. - * - * ``` php - * dontSeeInCurrentUrl('/users/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() - */ - public function dontSeeInCurrentUrl($uri) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInCurrentUrl', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current URI doesn't contain the given string. - * - * ``` php - * dontSeeInCurrentUrl('/users/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() - */ - public function cantSeeInCurrentUrl($uri) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeInCurrentUrl', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URL is equal to the given string. - * Unlike `seeInCurrentUrl`, this only matches the full URL. - * - * ``` php - * seeCurrentUrlEquals('/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() - */ - public function seeCurrentUrlEquals($uri) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlEquals', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current URL is equal to the given string. - * Unlike `seeInCurrentUrl`, this only matches the full URL. - * - * ``` php - * seeCurrentUrlEquals('/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() - */ - public function canSeeCurrentUrlEquals($uri) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeCurrentUrlEquals', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URL doesn't equal the given string. - * Unlike `dontSeeInCurrentUrl`, this only matches the full URL. - * - * ``` php - * dontSeeCurrentUrlEquals('/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() - */ - public function dontSeeCurrentUrlEquals($uri) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeCurrentUrlEquals', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current URL doesn't equal the given string. - * Unlike `dontSeeInCurrentUrl`, this only matches the full URL. - * - * ``` php - * dontSeeCurrentUrlEquals('/'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() - */ - public function cantSeeCurrentUrlEquals($uri) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlEquals', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URL matches the given regular expression. - * - * ``` php - * seeCurrentUrlMatches('~^/users/(\d+)~'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() - */ - public function seeCurrentUrlMatches($uri) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlMatches', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the current URL matches the given regular expression. - * - * ``` php - * seeCurrentUrlMatches('~^/users/(\d+)~'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() - */ - public function canSeeCurrentUrlMatches($uri) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeCurrentUrlMatches', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that current url doesn't match the given regular expression. - * - * ``` php - * dontSeeCurrentUrlMatches('~^/users/(\d+)~'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() - */ - public function dontSeeCurrentUrlMatches($uri) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeCurrentUrlMatches', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that current url doesn't match the given regular expression. - * - * ``` php - * dontSeeCurrentUrlMatches('~^/users/(\d+)~'); - * ?> - * ``` - * - * @param string $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() - */ - public function cantSeeCurrentUrlMatches($uri) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlMatches', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Executes the given regular expression against the current URI and returns the first capturing group. - * If no parameters are provided, the full URI is returned. - * - * ``` php - * grabFromCurrentUrl('~^/user/(\d+)/~'); - * $uri = $I->grabFromCurrentUrl(); - * ?> - * ``` - * - * @param string $uri optional - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabFromCurrentUrl() - */ - public function grabFromCurrentUrl($uri = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromCurrentUrl', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the specified checkbox is checked. - * - * ``` php - * seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms - * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. - * $I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); - * ?> - * ``` - * - * @param $checkbox - * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() - */ - public function seeCheckboxIsChecked($checkbox) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCheckboxIsChecked', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the specified checkbox is checked. - * - * ``` php - * seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms - * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. - * $I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); - * ?> - * ``` - * - * @param $checkbox - * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() - */ - public function canSeeCheckboxIsChecked($checkbox) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeCheckboxIsChecked', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Check that the specified checkbox is unchecked. - * - * ``` php - * dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms - * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. - * ?> - * ``` - * - * @param $checkbox - * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() - */ - public function dontSeeCheckboxIsChecked($checkbox) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeCheckboxIsChecked', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Check that the specified checkbox is unchecked. - * - * ``` php - * dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms - * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. - * ?> - * ``` - * - * @param $checkbox - * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() - */ - public function cantSeeCheckboxIsChecked($checkbox) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeCheckboxIsChecked', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given input field or textarea *equals* (i.e. not just contains) the given value. - * Fields are matched by label text, the "name" attribute, CSS, or XPath. - * - * ``` php - * seeInField('Body','Type your comment here'); - * $I->seeInField('form textarea[name=body]','Type your comment here'); - * $I->seeInField('form input[type=hidden]','hidden_value'); - * $I->seeInField('#searchform input','Search'); - * $I->seeInField('//form/*[@name=search]','Search'); - * $I->seeInField(['name' => 'search'], 'Search'); - * ?> - * ``` - * - * @param $field - * @param $value - * @see \Codeception\Lib\InnerBrowser::seeInField() - */ - public function seeInField($field, $value) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInField', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the given input field or textarea *equals* (i.e. not just contains) the given value. - * Fields are matched by label text, the "name" attribute, CSS, or XPath. - * - * ``` php - * seeInField('Body','Type your comment here'); - * $I->seeInField('form textarea[name=body]','Type your comment here'); - * $I->seeInField('form input[type=hidden]','hidden_value'); - * $I->seeInField('#searchform input','Search'); - * $I->seeInField('//form/*[@name=search]','Search'); - * $I->seeInField(['name' => 'search'], 'Search'); - * ?> - * ``` - * - * @param $field - * @param $value - * @see \Codeception\Lib\InnerBrowser::seeInField() - */ - public function canSeeInField($field, $value) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInField', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that an input field or textarea doesn't contain the given value. - * For fuzzy locators, the field is matched by label text, CSS and XPath. - * - * ``` php - * dontSeeInField('Body','Type your comment here'); - * $I->dontSeeInField('form textarea[name=body]','Type your comment here'); - * $I->dontSeeInField('form input[type=hidden]','hidden_value'); - * $I->dontSeeInField('#searchform input','Search'); - * $I->dontSeeInField('//form/*[@name=search]','Search'); - * $I->dontSeeInField(['name' => 'search'], 'Search'); - * ?> - * ``` - * - * @param $field - * @param $value - * @see \Codeception\Lib\InnerBrowser::dontSeeInField() - */ - public function dontSeeInField($field, $value) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInField', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that an input field or textarea doesn't contain the given value. - * For fuzzy locators, the field is matched by label text, CSS and XPath. - * - * ``` php - * dontSeeInField('Body','Type your comment here'); - * $I->dontSeeInField('form textarea[name=body]','Type your comment here'); - * $I->dontSeeInField('form input[type=hidden]','hidden_value'); - * $I->dontSeeInField('#searchform input','Search'); - * $I->dontSeeInField('//form/*[@name=search]','Search'); - * $I->dontSeeInField(['name' => 'search'], 'Search'); - * ?> - * ``` - * - * @param $field - * @param $value - * @see \Codeception\Lib\InnerBrowser::dontSeeInField() - */ - public function cantSeeInField($field, $value) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeInField', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if the array of form parameters (name => value) are set on the form matched with the - * passed selector. - * - * ``` php - * seeInFormFields('form[name=myform]', [ - * 'input1' => 'value', - * 'input2' => 'other value', - * ]); - * ?> - * ``` - * - * For multi-select elements, or to check values of multiple elements with the same name, an - * array may be passed: - * - * ``` php - * seeInFormFields('.form-class', [ - * 'multiselect' => [ - * 'value1', - * 'value2', - * ], - * 'checkbox[]' => [ - * 'a checked value', - * 'another checked value', - * ], - * ]); - * ?> - * ``` - * - * Additionally, checkbox values can be checked with a boolean. - * - * ``` php - * seeInFormFields('#form-id', [ - * 'checkbox1' => true, // passes if checked - * 'checkbox2' => false, // passes if unchecked - * ]); - * ?> - * ``` - * - * Pair this with submitForm for quick testing magic. - * - * ``` php - * 'value', - * 'field2' => 'another value', - * 'checkbox1' => true, - * // ... - * ]; - * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); - * // $I->amOnPage('/path/to/form-page') may be needed - * $I->seeInFormFields('//form[@id=my-form]', $form); - * ?> - * ``` - * - * @param $formSelector - * @param $params - * @see \Codeception\Lib\InnerBrowser::seeInFormFields() - */ - public function seeInFormFields($formSelector, array $params) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInFormFields', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks if the array of form parameters (name => value) are set on the form matched with the - * passed selector. - * - * ``` php - * seeInFormFields('form[name=myform]', [ - * 'input1' => 'value', - * 'input2' => 'other value', - * ]); - * ?> - * ``` - * - * For multi-select elements, or to check values of multiple elements with the same name, an - * array may be passed: - * - * ``` php - * seeInFormFields('.form-class', [ - * 'multiselect' => [ - * 'value1', - * 'value2', - * ], - * 'checkbox[]' => [ - * 'a checked value', - * 'another checked value', - * ], - * ]); - * ?> - * ``` - * - * Additionally, checkbox values can be checked with a boolean. - * - * ``` php - * seeInFormFields('#form-id', [ - * 'checkbox1' => true, // passes if checked - * 'checkbox2' => false, // passes if unchecked - * ]); - * ?> - * ``` - * - * Pair this with submitForm for quick testing magic. - * - * ``` php - * 'value', - * 'field2' => 'another value', - * 'checkbox1' => true, - * // ... - * ]; - * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); - * // $I->amOnPage('/path/to/form-page') may be needed - * $I->seeInFormFields('//form[@id=my-form]', $form); - * ?> - * ``` - * - * @param $formSelector - * @param $params - * @see \Codeception\Lib\InnerBrowser::seeInFormFields() - */ - public function canSeeInFormFields($formSelector, array $params) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeInFormFields', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if the array of form parameters (name => value) are not set on the form matched with - * the passed selector. - * - * ``` php - * dontSeeInFormFields('form[name=myform]', [ - * 'input1' => 'non-existent value', - * 'input2' => 'other non-existent value', - * ]); - * ?> - * ``` - * - * To check that an element hasn't been assigned any one of many values, an array can be passed - * as the value: - * - * ``` php - * dontSeeInFormFields('.form-class', [ - * 'fieldName' => [ - * 'This value shouldn\'t be set', - * 'And this value shouldn\'t be set', - * ], - * ]); - * ?> - * ``` - * - * Additionally, checkbox values can be checked with a boolean. - * - * ``` php - * dontSeeInFormFields('#form-id', [ - * 'checkbox1' => true, // fails if checked - * 'checkbox2' => false, // fails if unchecked - * ]); - * ?> - * ``` - * - * @param $formSelector - * @param $params - * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() - */ - public function dontSeeInFormFields($formSelector, array $params) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInFormFields', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks if the array of form parameters (name => value) are not set on the form matched with - * the passed selector. - * - * ``` php - * dontSeeInFormFields('form[name=myform]', [ - * 'input1' => 'non-existent value', - * 'input2' => 'other non-existent value', - * ]); - * ?> - * ``` - * - * To check that an element hasn't been assigned any one of many values, an array can be passed - * as the value: - * - * ``` php - * dontSeeInFormFields('.form-class', [ - * 'fieldName' => [ - * 'This value shouldn\'t be set', - * 'And this value shouldn\'t be set', - * ], - * ]); - * ?> - * ``` - * - * Additionally, checkbox values can be checked with a boolean. - * - * ``` php - * dontSeeInFormFields('#form-id', [ - * 'checkbox1' => true, // fails if checked - * 'checkbox2' => false, // fails if unchecked - * ]); - * ?> - * ``` - * - * @param $formSelector - * @param $params - * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() - */ - public function cantSeeInFormFields($formSelector, array $params) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeInFormFields', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Submits the given form on the page, with the given form - * values. Pass the form field's values as an array in the second - * parameter. - * - * Although this function can be used as a short-hand version of - * `fillField()`, `selectOption()`, `click()` etc. it has some important - * differences: - * - * * Only field *names* may be used, not CSS/XPath selectors nor field labels - * * If a field is sent to this function that does *not* exist on the page, - * it will silently be added to the HTTP request. This is helpful for testing - * some types of forms, but be aware that you will *not* get an exception - * like you would if you called `fillField()` or `selectOption()` with - * a missing field. - * - * Fields that are not provided will be filled by their values from the page, - * or from any previous calls to `fillField()`, `selectOption()` etc. - * You don't need to click the 'Submit' button afterwards. - * This command itself triggers the request to form's action. - * - * You can optionally specify which button's value to include - * in the request with the last parameter (as an alternative to - * explicitly setting its value in the second parameter), as - * button values are not otherwise included in the request. - * - * Examples: - * - * ``` php - * submitForm('#login', [ - * 'login' => 'davert', - * 'password' => '123456' - * ]); - * // or - * $I->submitForm('#login', [ - * 'login' => 'davert', - * 'password' => '123456' - * ], 'submitButtonName'); - * - * ``` - * - * For example, given this sample "Sign Up" form: - * - * ``` html - *
- * Login: - *
- * Password: - *
- * Do you agree to our terms? - *
- * Subscribe to our newsletter? - *
- * Select pricing plan: - * - * - *
- * ``` - * - * You could write the following to submit it: - * - * ``` php - * submitForm( - * '#userForm', - * [ - * 'user' => [ - * 'login' => 'Davert', - * 'password' => '123456', - * 'agree' => true - * ] - * ], - * 'submitButton' - * ); - * ``` - * Note that "2" will be the submitted value for the "plan" field, as it is - * the selected option. - * - * To uncheck the pre-checked checkbox "newsletter", call `$I->uncheckOption(['name' => 'user[newsletter]']);` *before*, - * then submit the form as shown here (i.e. without the "newsletter" field in the `$params` array). - * - * You can also emulate a JavaScript submission by not specifying any - * buttons in the third parameter to submitForm. - * - * ```php - * submitForm( - * '#userForm', - * [ - * 'user' => [ - * 'login' => 'Davert', - * 'password' => '123456', - * 'agree' => true - * ] - * ] - * ); - * ``` - * - * This function works well when paired with `seeInFormFields()` - * for quickly testing CRUD interfaces and form validation logic. - * - * ``` php - * 'value', - * 'field2' => 'another value', - * 'checkbox1' => true, - * // ... - * ]; - * $I->submitForm('#my-form', $form, 'submitButton'); - * // $I->amOnPage('/path/to/form-page') may be needed - * $I->seeInFormFields('#my-form', $form); - * ``` - * - * Parameter values can be set to arrays for multiple input fields - * of the same name, or multi-select combo boxes. For checkboxes, - * you can use either the string value or boolean `true`/`false` which will - * be replaced by the checkbox's value in the DOM. - * - * ``` php - * submitForm('#my-form', [ - * 'field1' => 'value', - * 'checkbox' => [ - * 'value of first checkbox', - * 'value of second checkbox', - * ], - * 'otherCheckboxes' => [ - * true, - * false, - * false - * ], - * 'multiselect' => [ - * 'first option value', - * 'second option value' - * ] - * ]); - * ``` - * - * Mixing string and boolean values for a checkbox's value is not supported - * and may produce unexpected results. - * - * Field names ending in `[]` must be passed without the trailing square - * bracket characters, and must contain an array for its value. This allows - * submitting multiple values with the same name, consider: - * - * ```php - * submitForm('#my-form', [ - * 'field[]' => 'value', - * 'field[]' => 'another value', // 'field[]' is already a defined key - * ]); - * ``` - * - * The solution is to pass an array value: - * - * ```php - * submitForm('#my-form', [ - * 'field' => [ - * 'value', - * 'another value', - * ] - * ]); - * ``` - * - * @param $selector - * @param $params - * @param $button - * @see \Codeception\Lib\InnerBrowser::submitForm() - */ - public function submitForm($selector, array $params, $button = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('submitForm', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Fills a text field or textarea with the given string. - * - * ``` php - * fillField("//input[@type='text']", "Hello World!"); - * $I->fillField(['name' => 'email'], 'jon@example.com'); - * ?> - * ``` - * - * @param $field - * @param $value - * @see \Codeception\Lib\InnerBrowser::fillField() - */ - public function fillField($field, $value) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('fillField', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Selects an option in a select tag or in radio button group. - * - * ``` php - * selectOption('form select[name=account]', 'Premium'); - * $I->selectOption('form input[name=payment]', 'Monthly'); - * $I->selectOption('//form/select[@name=account]', 'Monthly'); - * ?> - * ``` - * - * Provide an array for the second argument to select multiple options: - * - * ``` php - * selectOption('Which OS do you use?', array('Windows','Linux')); - * ?> - * ``` - * - * Or provide an associative array for the second argument to specifically define which selection method should be used: - * - * ``` php - * selectOption('Which OS do you use?', array('text' => 'Windows')); // Only search by text 'Windows' - * $I->selectOption('Which OS do you use?', array('value' => 'windows')); // Only search by value 'windows' - * ?> - * ``` - * - * @param $select - * @param $option - * @see \Codeception\Lib\InnerBrowser::selectOption() - */ - public function selectOption($select, $option) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('selectOption', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Ticks a checkbox. For radio buttons, use the `selectOption` method instead. - * - * ``` php - * checkOption('#agree'); - * ?> - * ``` - * - * @param $option - * @see \Codeception\Lib\InnerBrowser::checkOption() - */ - public function checkOption($option) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('checkOption', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Unticks a checkbox. - * - * ``` php - * uncheckOption('#notify'); - * ?> - * ``` - * - * @param $option - * @see \Codeception\Lib\InnerBrowser::uncheckOption() - */ - public function uncheckOption($option) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('uncheckOption', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Attaches a file relative to the Codeception `_data` directory to the given file upload field. - * - * ``` php - * attachFile('input[@type="file"]', 'prices.xls'); - * ?> - * ``` - * - * @param $field - * @param $filename - * @see \Codeception\Lib\InnerBrowser::attachFile() - */ - public function attachFile($field, $filename) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('attachFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Sends an ajax GET request with the passed parameters. - * See `sendAjaxPostRequest()` - * - * @param $uri - * @param $params - * @see \Codeception\Lib\InnerBrowser::sendAjaxGetRequest() - */ - public function sendAjaxGetRequest($uri, $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxGetRequest', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Sends an ajax POST request with the passed parameters. - * The appropriate HTTP header is added automatically: - * `X-Requested-With: XMLHttpRequest` - * Example: - * ``` php - * sendAjaxPostRequest('/add-task', ['task' => 'lorem ipsum']); - * ``` - * Some frameworks (e.g. Symfony) create field names in the form of an "array": - * `` - * In this case you need to pass the fields like this: - * ``` php - * sendAjaxPostRequest('/add-task', ['form' => [ - * 'task' => 'lorem ipsum', - * 'category' => 'miscellaneous', - * ]]); - * ``` - * - * @param string $uri - * @param array $params - * @see \Codeception\Lib\InnerBrowser::sendAjaxPostRequest() - */ - public function sendAjaxPostRequest($uri, $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxPostRequest', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Sends an ajax request, using the passed HTTP method. - * See `sendAjaxPostRequest()` - * Example: - * ``` php - * sendAjaxRequest('PUT', '/posts/7', ['title' => 'new title']); - * ``` - * - * @param $method - * @param $uri - * @param array $params - * @see \Codeception\Lib\InnerBrowser::sendAjaxRequest() - */ - public function sendAjaxRequest($method, $uri, $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxRequest', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Use this method within an [interactive pause](https://codeception.com/docs/02-GettingStarted#Interactive-Pause) to save the HTML source code of the current page. - * - * ```php - * makeHtmlSnapshot('edit_page'); - * // saved to: tests/_output/debug/edit_page.html - * $I->makeHtmlSnapshot(); - * // saved to: tests/_output/debug/2017-05-26_14-24-11_4b3403665fea6.html - * ``` - * - * @param null $name - * @see \Codeception\Lib\InnerBrowser::makeHtmlSnapshot() - */ - public function makeHtmlSnapshot($name = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('makeHtmlSnapshot', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Finds and returns the text contents of the given element. - * If a fuzzy locator is used, the element is found using CSS, XPath, - * and by matching the full page source by regular expression. - * - * ``` php - * grabTextFrom('h1'); - * $heading = $I->grabTextFrom('descendant-or-self::h1'); - * $value = $I->grabTextFrom('~ - * ``` - * - * @param $cssOrXPathOrRegex - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabTextFrom() - */ - public function grabTextFrom($cssOrXPathOrRegex) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabTextFrom', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Grabs the value of the given attribute value from the given element. - * Fails if element is not found. - * - * ``` php - * grabAttributeFrom('#tooltip', 'title'); - * ?> - * ``` - * - * - * @param $cssOrXpath - * @param $attribute - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabAttributeFrom() - */ - public function grabAttributeFrom($cssOrXpath, $attribute) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabAttributeFrom', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Grabs either the text content, or attribute values, of nodes - * matched by $cssOrXpath and returns them as an array. - * - * ```html - * First - * Second - * Third - * ``` - * - * ```php - * grabMultiple('a'); - * - * // would return ['#first', '#second', '#third'] - * $aLinks = $I->grabMultiple('a', 'href'); - * ?> - * ``` - * - * @param $cssOrXpath - * @param $attribute - * @return string[] - * @see \Codeception\Lib\InnerBrowser::grabMultiple() - */ - public function grabMultiple($cssOrXpath, $attribute = null) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabMultiple', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $field - * - * @return array|mixed|null|string - * @see \Codeception\Lib\InnerBrowser::grabValueFrom() - */ - public function grabValueFrom($field) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabValueFrom', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Sets a cookie with the given name and value. - * You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. - * - * ``` php - * setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); - * ?> - * ``` - * - * @param $name - * @param $val - * @param array $params - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::setCookie() - */ - public function setCookie($name, $val, array $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('setCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Grabs a cookie value. - * You can set additional cookie params like `domain`, `path` in array passed as last argument. - * If the cookie is set by an ajax request (XMLHttpRequest), there might be some delay caused by the browser, so try `$I->wait(0.1)`. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabCookie() - */ - public function grabCookie($cookie, array $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Grabs current page source code. - * - * @return string Current page source code. - * @throws ModuleException if no page was opened. - * @see \Codeception\Lib\InnerBrowser::grabPageSource() - */ - public function grabPageSource() - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabPageSource', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that a cookie with the given name is set. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * ``` php - * seeCookie('PHPSESSID'); - * ?> - * ``` - * - * @param $cookie - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeCookie() - */ - public function seeCookie($cookie, array $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCookie', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that a cookie with the given name is set. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * ``` php - * seeCookie('PHPSESSID'); - * ?> - * ``` - * - * @param $cookie - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeCookie() - */ - public function canSeeCookie($cookie, array $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there isn't a cookie with the given name. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() - */ - public function dontSeeCookie($cookie, array $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeCookie', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that there isn't a cookie with the given name. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() - */ - public function cantSeeCookie($cookie, array $params = []) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeCookie', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Unsets cookie with the given name. - * You can set additional cookie params like `domain`, `path` in array passed as last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::resetCookie() - */ - public function resetCookie($cookie, array $params = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('resetCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given element exists on the page and is visible. - * You can also specify expected attributes of this element. - * - * ``` php - * seeElement('.error'); - * $I->seeElement('//form/input[1]'); - * $I->seeElement('input', ['name' => 'login']); - * $I->seeElement('input', ['value' => '123456']); - * - * // strict locator in first arg, attributes in second - * $I->seeElement(['css' => 'form input'], ['name' => 'login']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @return - * @see \Codeception\Lib\InnerBrowser::seeElement() - */ - public function seeElement($selector, $attributes = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeElement', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the given element exists on the page and is visible. - * You can also specify expected attributes of this element. - * - * ``` php - * seeElement('.error'); - * $I->seeElement('//form/input[1]'); - * $I->seeElement('input', ['name' => 'login']); - * $I->seeElement('input', ['value' => '123456']); - * - * // strict locator in first arg, attributes in second - * $I->seeElement(['css' => 'form input'], ['name' => 'login']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @return - * @see \Codeception\Lib\InnerBrowser::seeElement() - */ - public function canSeeElement($selector, $attributes = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeElement', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given element is invisible or not present on the page. - * You can also specify expected attributes of this element. - * - * ``` php - * dontSeeElement('.error'); - * $I->dontSeeElement('//form/input[1]'); - * $I->dontSeeElement('input', ['name' => 'login']); - * $I->dontSeeElement('input', ['value' => '123456']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @see \Codeception\Lib\InnerBrowser::dontSeeElement() - */ - public function dontSeeElement($selector, $attributes = []) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeElement', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the given element is invisible or not present on the page. - * You can also specify expected attributes of this element. - * - * ``` php - * dontSeeElement('.error'); - * $I->dontSeeElement('//form/input[1]'); - * $I->dontSeeElement('input', ['name' => 'login']); - * $I->dontSeeElement('input', ['value' => '123456']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @see \Codeception\Lib\InnerBrowser::dontSeeElement() - */ - public function cantSeeElement($selector, $attributes = []) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeElement', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there are a certain number of elements matched by the given locator on the page. - * - * ``` php - * seeNumberOfElements('tr', 10); - * $I->seeNumberOfElements('tr', [0,10]); // between 0 and 10 elements - * ?> - * ``` - * @param $selector - * @param mixed $expected int or int[] - * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() - */ - public function seeNumberOfElements($selector, $expected) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElements', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that there are a certain number of elements matched by the given locator on the page. - * - * ``` php - * seeNumberOfElements('tr', 10); - * $I->seeNumberOfElements('tr', [0,10]); // between 0 and 10 elements - * ?> - * ``` - * @param $selector - * @param mixed $expected int or int[] - * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() - */ - public function canSeeNumberOfElements($selector, $expected) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeNumberOfElements', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given option is selected. - * - * ``` php - * seeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() - */ - public function seeOptionIsSelected($selector, $optionText) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeOptionIsSelected', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the given option is selected. - * - * ``` php - * seeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() - */ - public function canSeeOptionIsSelected($selector, $optionText) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeOptionIsSelected', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given option is not selected. - * - * ``` php - * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() - */ - public function dontSeeOptionIsSelected($selector, $optionText) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeOptionIsSelected', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the given option is not selected. - * - * ``` php - * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() - */ - public function cantSeeOptionIsSelected($selector, $optionText) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeOptionIsSelected', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Asserts that current page has 404 response status code. - * @see \Codeception\Lib\InnerBrowser::seePageNotFound() - */ - public function seePageNotFound() - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seePageNotFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Asserts that current page has 404 response status code. - * @see \Codeception\Lib\InnerBrowser::seePageNotFound() - */ - public function canSeePageNotFound() - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seePageNotFound', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is equal to value provided. - * - * ```php - * seeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * - * @param int $code - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() - */ - public function seeResponseCodeIs($code) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIs', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that response code is equal to value provided. - * - * ```php - * seeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * - * @param int $code - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() - */ - public function canSeeResponseCodeIs($code) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeResponseCodeIs', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is between a certain range. Between actually means [from <= CODE <= to] - * - * @param int $from - * @param int $to - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsBetween() - */ - public function seeResponseCodeIsBetween($from, $to) - { - return $this->getScenario()->runStep( - new \Codeception\Step\Assertion('seeResponseCodeIsBetween', func_get_args()) - ); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that response code is between a certain range. Between actually means [from <= CODE <= to] - * - * @param int $from - * @param int $to - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsBetween() - */ - public function canSeeResponseCodeIsBetween($from, $to) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsBetween', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is equal to value provided. - * - * ```php - * dontSeeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * @param int $code - * @see \Codeception\Lib\InnerBrowser::dontSeeResponseCodeIs() - */ - public function dontSeeResponseCodeIs($code) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeResponseCodeIs', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that response code is equal to value provided. - * - * ```php - * dontSeeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * @param int $code - * @see \Codeception\Lib\InnerBrowser::dontSeeResponseCodeIs() - */ - public function cantSeeResponseCodeIs($code) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeResponseCodeIs', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the response code 2xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsSuccessful() - */ - public function seeResponseCodeIsSuccessful() - { - return $this->getScenario()->runStep( - new \Codeception\Step\Assertion('seeResponseCodeIsSuccessful', func_get_args()) - ); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the response code 2xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsSuccessful() - */ - public function canSeeResponseCodeIsSuccessful() - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsSuccessful', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the response code 3xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsRedirection() - */ - public function seeResponseCodeIsRedirection() - { - return $this->getScenario()->runStep( - new \Codeception\Step\Assertion('seeResponseCodeIsRedirection', func_get_args()) - ); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the response code 3xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsRedirection() - */ - public function canSeeResponseCodeIsRedirection() - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsRedirection', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the response code is 4xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsClientError() - */ - public function seeResponseCodeIsClientError() - { - return $this->getScenario()->runStep( - new \Codeception\Step\Assertion('seeResponseCodeIsClientError', func_get_args()) - ); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the response code is 4xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsClientError() - */ - public function canSeeResponseCodeIsClientError() - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsClientError', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the response code is 5xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsServerError() - */ - public function seeResponseCodeIsServerError() - { - return $this->getScenario()->runStep( - new \Codeception\Step\Assertion('seeResponseCodeIsServerError', func_get_args()) - ); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the response code is 5xx - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsServerError() - */ - public function canSeeResponseCodeIsServerError() - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsServerError', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page title contains the given string. - * - * ``` php - * seeInTitle('Blog - Post #1'); - * ?> - * ``` - * - * @param $title - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeInTitle() - */ - public function seeInTitle($title) - { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInTitle', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the page title contains the given string. - * - * ``` php - * seeInTitle('Blog - Post #1'); - * ?> - * ``` - * - * @param $title - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeInTitle() - */ - public function canSeeInTitle($title) - { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInTitle', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page title does not contain the given string. - * - * @param $title - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() - */ - public function dontSeeInTitle($title) - { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInTitle', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * [!] Conditional Assertion: Test won't be stopped on fail - * Checks that the page title does not contain the given string. - * - * @param $title - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() - */ - public function cantSeeInTitle($title) - { - return $this->getScenario()->runStep( - new \Codeception\Step\ConditionalAssertion('dontSeeInTitle', func_get_args()) - ); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Switch to iframe or frame on the page. - * - * Example: - * ``` html - *