From d2d33a20c5b97ca72985b2750bc16d5dbb7feb02 Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Sat, 27 Jul 2019 13:59:50 +0200 Subject: [PATCH] Sync with master (#912) * #875: Swiftmailer and Twig are no longer required Moved Swiftmailer and Twig to the Composer "suggest" * Add new validator: ArrayInclusionIn * Fix unit test * Fix unit test - last test method * Support for the TIMESTAMPDIFF * Add options to ReCaptcha Validator to make it work with v3. * Fixed PHPCS issues * fix(oracle): Added missing interface method sharedLock * Moved opening brace to newline as suggested Co-Authored-By: lubber-de * Translate Adapter for multi-column csv (#890) * [Translate] add an intl MessageFormatter interpolator (#892) * Tidied up READMEs. * Applied PSR2 to tests. * Code standards. * Tidied up Annotations. * Tidied up codebase. --- .../Annotations/Extended/Adapter/Apc.php | 6 +- .../Annotations/Extended/Adapter/Files.php | 3 +- Library/Phalcon/Db/Dialect/Oracle.php | 57 +++--- Library/Phalcon/Error/Handler.php | 3 +- Library/Phalcon/Mailer/Manager.php | 37 ++-- Library/Phalcon/Mailer/Message.php | 36 ++-- .../Phalcon/Mvc/Model/EagerLoading/Loader.php | 35 ++-- .../Mvc/Model/EagerLoading/QueryBuilder.php | 7 +- .../Phalcon/Mvc/Model/EagerLoadingTrait.php | 15 +- Library/Phalcon/Mvc/View/Engine/Twig.php | 101 +++++----- Library/Phalcon/Paginator/Pager.php | 38 ++-- Library/Phalcon/Session/Adapter/Mongo.php | 14 +- .../Test/Traits/FunctionalTestCase.php | 29 ++- .../Phalcon/Translate/Adapter/CsvMulti.php | 23 +-- .../Phalcon/Translate/Adapter/Database.php | 7 +- Library/Phalcon/Translate/Adapter/Mongo.php | 5 +- Library/Phalcon/Translate/Adapter/Redis.php | 6 +- .../Translate/Adapter/ResourceBundle.php | 4 +- .../Phalcon/Translate/Interpolator/Intl.php | 9 +- .../Validator/AlphaNamesValidator.php | 9 +- .../Validator/AlphaNumericValidator.php | 9 +- .../Validation/Validator/ArrayInclusionIn.php | 12 +- .../Validation/Validator/CardNumber.php | 14 +- .../Validation/Validator/NumericValidator.php | 8 +- composer.json | 22 +-- tests/_bootstrap.php | 4 +- tests/unit/Validation/Validator/IbanTest.php | 9 +- .../Validation/Validator/MongoIdTest.php | 178 ++++++++++++++++++ 28 files changed, 413 insertions(+), 287 deletions(-) create mode 100644 tests/unit5x/Validation/Validator/MongoIdTest.php diff --git a/Library/Phalcon/Annotations/Extended/Adapter/Apc.php b/Library/Phalcon/Annotations/Extended/Adapter/Apc.php index 8e3c02be7..460b62336 100644 --- a/Library/Phalcon/Annotations/Extended/Adapter/Apc.php +++ b/Library/Phalcon/Annotations/Extended/Adapter/Apc.php @@ -19,8 +19,6 @@ namespace Phalcon\Annotations\Extended\Adapter; -use APCIterator; -use APCuIterator; use Phalcon\Annotations\Exception; use Phalcon\Annotations\Reflection; use Phalcon\Annotations\Extended\AbstractAdapter; @@ -145,7 +143,7 @@ public function flush() $prefixPattern = '#^_PHAN' . preg_quote("{$this->prefix}", '#') . '#'; if (class_exists('\APCuIterator')) { - $iterator = new APCuIterator($prefixPattern); + $iterator = new \APCuIterator($prefixPattern); foreach ($iterator as $item) { apcu_delete( @@ -156,7 +154,7 @@ public function flush() return true; } - $iterator = new APCIterator('user', $prefixPattern); + $iterator = new \APCIterator('user', $prefixPattern); foreach ($iterator as $item) { apc_delete( diff --git a/Library/Phalcon/Annotations/Extended/Adapter/Files.php b/Library/Phalcon/Annotations/Extended/Adapter/Files.php index 22f2f70c8..b8d87de6d 100644 --- a/Library/Phalcon/Annotations/Extended/Adapter/Files.php +++ b/Library/Phalcon/Annotations/Extended/Adapter/Files.php @@ -19,7 +19,6 @@ namespace Phalcon\Annotations\Extended\Adapter; -use DirectoryIterator; use Phalcon\Annotations\Exception; use Phalcon\Annotations\Reflection; use Phalcon\Annotations\Extended\AbstractAdapter; @@ -142,7 +141,7 @@ public function write($key, Reflection $reflection) */ public function flush() { - $iterator = new DirectoryIterator($this->annotationsDir); + $iterator = new \DirectoryIterator($this->annotationsDir); foreach ($iterator as $item) { if ($item->isDot() || !$item->isFile() || $item->getExtension() !== 'php') { diff --git a/Library/Phalcon/Db/Dialect/Oracle.php b/Library/Phalcon/Db/Dialect/Oracle.php index dc0b63c32..19756d96e 100644 --- a/Library/Phalcon/Db/Dialect/Oracle.php +++ b/Library/Phalcon/Db/Dialect/Oracle.php @@ -59,7 +59,7 @@ class Oracle extends Dialect * @param string $sqlQuery * @return string */ - public function sharedLock(string $sqlQuery): string + public function sharedLock($sqlQuery) { return $sqlQuery . ' LOCK IN SHARE MODE'; } @@ -71,7 +71,7 @@ public function sharedLock(string $sqlQuery): string * @param mixed $number * @return string */ - public function limit(string $sqlQuery, $number):string + public function limit($sqlQuery, $number) { $offset = 0; @@ -104,7 +104,7 @@ public function limit(string $sqlQuery, $number):string * * @throws Exception */ - public function getColumnDefinition(ColumnInterface $column): string + public function getColumnDefinition(ColumnInterface $column) { $type = $column->getType(); $size = $column->getSize(); @@ -159,7 +159,7 @@ public function getColumnDefinition(ColumnInterface $column): string * * @throws Exception */ - public function addColumn(string $tableName, string $schemaName, ColumnInterface $column): string + public function addColumn($tableName, $schemaName, ColumnInterface $column) { throw new Exception('Not implemented yet.'); } @@ -175,7 +175,7 @@ public function addColumn(string $tableName, string $schemaName, ColumnInterface * * @throws Exception */ - public function modifyColumn(string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $current = null): string + public function modifyColumn($tableName, $schemaName, ColumnInterface $column, ColumnInterface $current = null) { throw new Exception('Not implemented yet.'); } @@ -190,7 +190,7 @@ public function modifyColumn(string $tableName, string $schemaName, ColumnInterf * * @throws Exception */ - public function dropColumn(string $tableName, string $schemaName, string $columnName): string + public function dropColumn($tableName, $schemaName, $columnName) { throw new Exception('Not implemented yet.'); } @@ -205,7 +205,7 @@ public function dropColumn(string $tableName, string $schemaName, string $column * * @throws Exception */ - public function addIndex(string $tableName, string $schemaName, IndexInterface $index): string + public function addIndex($tableName, $schemaName, IndexInterface $index) { throw new Exception('Not implemented yet.'); } @@ -220,7 +220,7 @@ public function addIndex(string $tableName, string $schemaName, IndexInterface $ * * @throws Exception */ - public function dropIndex(string $tableName, string $schemaName, string $indexName): string + public function dropIndex($tableName, $schemaName, $indexName) { throw new Exception('Not implemented yet.'); } @@ -235,7 +235,7 @@ public function dropIndex(string $tableName, string $schemaName, string $indexNa * * @throws Exception */ - public function addPrimaryKey(string $tableName, string $schemaName, IndexInterface $index): string + public function addPrimaryKey($tableName, $schemaName, IndexInterface $index) { throw new Exception('Not implemented yet.'); } @@ -249,7 +249,7 @@ public function addPrimaryKey(string $tableName, string $schemaName, IndexInterf * * @throws Exception */ - public function dropPrimaryKey(string $tableName, string $schemaName): string + public function dropPrimaryKey($tableName, $schemaName) { throw new Exception('Not implemented yet.'); } @@ -264,7 +264,7 @@ public function dropPrimaryKey(string $tableName, string $schemaName): string * * @throws Exception */ - public function addForeignKey(string $tableName, string $schemaName, ReferenceInterface $reference): string + public function addForeignKey($tableName, $schemaName, ReferenceInterface $reference) { throw new Exception('Not implemented yet.'); } @@ -279,7 +279,7 @@ public function addForeignKey(string $tableName, string $schemaName, ReferenceIn * * @throws Exception */ - public function dropForeignKey(string $tableName, string $schemaName, string $referenceName): string + public function dropForeignKey($tableName, $schemaName, $referenceName) { throw new Exception('Not implemented yet.'); } @@ -294,7 +294,7 @@ public function dropForeignKey(string $tableName, string $schemaName, string $re * * @throws Exception */ - public function createTable(string $tableName, string $schemaName, array $definition): string + public function createTable($tableName, $schemaName, array $definition) { throw new Exception('Not implemented yet.'); } @@ -307,7 +307,7 @@ public function createTable(string $tableName, string $schemaName, array $defini * @param bool $ifExists * @return string */ - public function dropTable(string $tableName, string $schemaName, $ifExists = true): string + public function dropTable($tableName, $schemaName, $ifExists = true) { $this->_escapeChar = ''; @@ -340,7 +340,7 @@ public function dropTable(string $tableName, string $schemaName, $ifExists = tru * @param string $schemaName * @return string */ - public function listTables(string $schemaName = null): string + public function listTables($schemaName = null) { $baseQuery = /** @lang text */ "SELECT TABLE_NAME, OWNER FROM ALL_TABLES %s ORDER BY OWNER, TABLE_NAME"; @@ -366,7 +366,7 @@ public function listTables(string $schemaName = null): string * @param string $schemaName * @return string */ - public function tableExists(string $tableName, string $schemaName = null): string + public function tableExists($tableName, $schemaName = null) { $oldEscapeChar=$this->_escapeChar; @@ -398,7 +398,7 @@ public function tableExists(string $tableName, string $schemaName = null): strin * * @throws Exception */ - public function createView(string $viewName, array $definition, string $schemaName = null): string + public function createView($viewName, array $definition, $schemaName = null) { if (!isset($definition['sql']) || empty($definition['sql'])) { throw new Exception("The index 'sql' is required in the definition array"); @@ -415,7 +415,7 @@ public function createView(string $viewName, array $definition, string $schemaNa * @param bool $ifExists * @return string */ - public function dropView(string $viewName, string $schemaName = null, $ifExists = true): string + public function dropView($viewName, $schemaName = null, $ifExists = true) { $this->_escapeChar = ''; @@ -446,7 +446,7 @@ public function dropView(string $viewName, string $schemaName = null, $ifExists * * @return string */ - public function viewExists(string $viewName, string $schemaName = null): string + public function viewExists($viewName, $schemaName = null) { $view = $this->prepareTable($viewName, $schemaName); $baseSql = sprintf( @@ -491,7 +491,7 @@ public function listViews($schemaName = null) * @param string $schema * @return string */ - public function describeColumns(string $table, string $schema = null): string + public function describeColumns($table, $schema = null) { $oldEscapeChar= $this->_escapeChar; $this->_escapeChar = "'"; @@ -522,7 +522,7 @@ public function describeColumns(string $table, string $schema = null): string * @param string $schema * @return string */ - public function describeIndexes(string $table, string $schema = null): string + public function describeIndexes($table, $schema = null) { $table = $this->escape($table); $sql = 'SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME ' . @@ -538,12 +538,7 @@ public function describeIndexes(string $table, string $schema = null): string return $sql; } - /** - * @param string $table - * @param string|null $schema - * @return string - */ - public function describeReferences(string $table, string $schema = null): string + public function describeReferences($table, $schema = null) { $table = $this->escape($table); @@ -569,7 +564,7 @@ public function describeReferences(string $table, string $schema = null): string * @param string $schema * @return string */ - public function tableOptions(string $table, string $schema = null): string + public function tableOptions($table, $schema = null) { return ''; } @@ -579,7 +574,7 @@ public function tableOptions(string $table, string $schema = null): string * * @return bool */ - public function supportsSavepoints(): bool + public function supportsSavepoints() { return false; } @@ -589,7 +584,7 @@ public function supportsSavepoints(): bool * * @return bool */ - public function supportsReleaseSavepoints(): bool + public function supportsReleaseSavepoints() { return false; } @@ -603,7 +598,7 @@ public function supportsReleaseSavepoints(): bool * @param string $escapeChar * @return string */ - protected function prepareTable(string $table, string $schema = null, string $alias = null, string $escapeChar = null): string + protected function prepareTable($table, $schema = null, $alias = null, $escapeChar = null) { $table = $this->escape($table, $escapeChar); diff --git a/Library/Phalcon/Error/Handler.php b/Library/Phalcon/Error/Handler.php index c1ce3c11c..6bd10bad6 100644 --- a/Library/Phalcon/Error/Handler.php +++ b/Library/Phalcon/Error/Handler.php @@ -22,7 +22,6 @@ namespace Phalcon\Error; -use Exception; use Phalcon\Di; use Phalcon\DiInterface; use Phalcon\Logger\Formatter; @@ -77,7 +76,7 @@ function ($errno, $errstr, $errfile, $errline) { set_exception_handler( function ($e) { - /** @var Exception|\Error $e */ + /** @var \Exception|\Error $e */ $options = [ 'type' => $e->getCode(), 'message' => $e->getMessage(), diff --git a/Library/Phalcon/Mailer/Manager.php b/Library/Phalcon/Mailer/Manager.php index 3c15d856a..fd8d55c06 100644 --- a/Library/Phalcon/Mailer/Manager.php +++ b/Library/Phalcon/Mailer/Manager.php @@ -19,16 +19,9 @@ namespace Phalcon\Mailer; -use InvalidArgumentException; use Phalcon\Config; use Phalcon\Mvc\User\Component; use Phalcon\Mvc\View; -use Phalcon\Mvc\View\Simple; -use Swift_Mailer; -use Swift_MailTransport; -use Swift_SendmailTransport; -use Swift_SmtpTransport; -use Swift_Transport; /** * Class Manager @@ -52,17 +45,17 @@ class Manager extends Component protected $config = []; /** - * @var Swift_Transport + * @var \Swift_Transport */ protected $transport; /** - * @var Swift_Mailer + * @var \Swift_Mailer */ protected $mailer; /** - * @var Simple + * @var \Phalcon\Mvc\View\Simple */ protected $view; @@ -88,7 +81,7 @@ public function __construct(array $config) * - mailer:beforeCreateMessage * - mailer:afterCreateMessage * - * @return Message + * @return \Phalcon\Mailer\Message */ public function createMessage() { @@ -132,7 +125,7 @@ public function createMessage() * @param array $params optional * @param null|string $viewsDir optional * - * @return Message + * @return \Phalcon\Mailer\Message * * @see \Phalcon\Mailer\Manager::createMessage() */ @@ -151,7 +144,7 @@ public function createMessageFromView($view, $params = [], $viewsDir = null) /** * Return a {@link \Swift_Mailer} instance * - * @return Swift_Mailer + * @return \Swift_Mailer */ public function getSwift() { @@ -229,7 +222,7 @@ protected function registerSwiftTransport() break; default: - throw new InvalidArgumentException( + throw new \InvalidArgumentException( sprintf( 'Driver-mail "%s" is not supported', $driver @@ -241,7 +234,7 @@ protected function registerSwiftTransport() /** * Create a new SmtpTransport instance. * - * @return Swift_SmtpTransport + * @return \Swift_SmtpTransport * * @see \Swift_SmtpTransport */ @@ -249,7 +242,7 @@ protected function registerTransportSmtp() { $config = $this->getConfig(); - /** @var $transport Swift_SmtpTransport: */ + /** @var $transport \Swift_SmtpTransport: */ $transport = $this->getDI()->get('\Swift_SmtpTransport') ->setHost($config['host']) ->setPort($config['port']); @@ -315,7 +308,7 @@ protected function punycode($str) /** * Create a new MailTransport instance. * - * @return Swift_MailTransport + * @return \Swift_MailTransport * * @see \Swift_MailTransport */ @@ -327,13 +320,13 @@ protected function registerTransportMail() /** * Create a new SendmailTransport instance. * - * @return Swift_SendmailTransport + * @return \Swift_SendmailTransport * * @see \Swift_SendmailTransport */ protected function registerTransportSendmail() { - /** @var $transport Swift_SendmailTransport */ + /** @var $transport \Swift_SendmailTransport */ $transport = $this->getDI()->get('\Swift_SendmailTransport') ->setCommand($this->getConfig('sendmail', '/usr/sbin/sendmail -bs')); @@ -384,19 +377,19 @@ protected function renderView($viewPath, $params, $viewsDir = null) /** * Return a {@link \Phalcon\Mvc\View\Simple} instance * - * @return Simple + * @return \Phalcon\Mvc\View\Simple */ protected function getView() { if (!$this->view) { - /** @var $viewApp View */ + /** @var $viewApp \Phalcon\Mvc\View */ $viewApp = $this->getDI()->get('view'); if (!($viewsDir = $this->getConfig('viewsDir'))) { $viewsDir = $viewApp->getViewsDir(); } - /** @var $view Simple */ + /** @var $view \Phalcon\Mvc\View\Simple */ $view = $this->getDI()->get('\Phalcon\Mvc\View\Simple'); $view->setViewsDir($viewsDir); diff --git a/Library/Phalcon/Mailer/Message.php b/Library/Phalcon/Mailer/Message.php index a4196a86b..f8a377df3 100644 --- a/Library/Phalcon/Mailer/Message.php +++ b/Library/Phalcon/Mailer/Message.php @@ -19,12 +19,6 @@ namespace Phalcon\Mailer; -use Swift_Attachment; -use Swift_ByteStream_FileByteStream; -use Swift_Image; -use Swift_Message; -use Traversable; - /** * Class Message * @@ -43,12 +37,12 @@ class Message const CONTENT_TYPE_HTML = 'text/html'; /** - * @var Manager + * @var \Phalcon\Mailer\Manager */ protected $manager; /** - * @var Swift_Message + * @var \Swift_Message */ protected $message; @@ -605,7 +599,7 @@ public function embedData($data, $name, $contentType = null) /** * Return a {@link \Swift_Message} instance * - * @return Swift_Message + * @return \Swift_Message */ public function getMessage() { @@ -619,7 +613,7 @@ public function getMessage() /** * Return a {@link \Phalcon\Mailer\Manager} instance * - * @return Manager + * @return \Phalcon\Mailer\Manager */ public function getManager() { @@ -683,14 +677,14 @@ public function send() /** * Prepare and attach the given attachment. * - * @param Swift_Attachment $attachment + * @param \Swift_Attachment $attachment * @param array $options optional * * @return $this * * @see \Swift_Message::attach() */ - protected function prepareAttachment(Swift_Attachment $attachment, array $options = []) + protected function prepareAttachment(\Swift_Attachment $attachment, array $options = []) { if (isset($options['mime'])) { $attachment->setContentType($options['mime']); @@ -736,13 +730,13 @@ protected function prepareAttachment(Swift_Attachment $attachment, array $option * * @param string $file * - * @return Swift_Attachment + * @return \Swift_Attachment * * @see \Swift_Attachment::fromPath() */ protected function createAttachmentViaPath($file) { - /** @var $byteStream Swift_ByteStream_FileByteStream */ + /** @var $byteStream \Swift_ByteStream_FileByteStream */ $byteStream = $this->getManager()->getDI()->get( '\Swift_ByteStream_FileByteStream', [ @@ -750,7 +744,7 @@ protected function createAttachmentViaPath($file) ] ); - /** @var $image Swift_Attachment */ + /** @var $image \Swift_Attachment */ $attachment = $this->getManager()->getDI()->get('\Swift_Attachment') ->setFile($byteStream); @@ -763,7 +757,7 @@ protected function createAttachmentViaPath($file) * @param string $data * @param string $name optional * - * @return Swift_Attachment + * @return \Swift_Attachment * * @see \Swift_Attachment::newInstance() */ @@ -783,13 +777,13 @@ protected function createAttachmentViaData($data, $name) * * @param string $file * - * @return Swift_Image + * @return \Swift_Image * * @see \Swift_Image::fromPath() */ protected function createEmbedViaPath($file) { - /** @var $byteStream Swift_ByteStream_FileByteStream */ + /** @var $byteStream \Swift_ByteStream_FileByteStream */ $byteStream = $this->getManager()->getDI()->get( '\Swift_ByteStream_FileByteStream', [ @@ -797,7 +791,7 @@ protected function createEmbedViaPath($file) ] ); - /** @var $image Swift_Image */ + /** @var $image \Swift_Image */ $image = $this->getManager()->getDI()->get('\Swift_Image') ->setFile($byteStream); @@ -810,7 +804,7 @@ protected function createEmbedViaPath($file) * @param string $data * @param string|null $name optional * - * @return Swift_Image + * @return \Swift_Image * * @see \Swift_Image::newInstance() */ @@ -834,7 +828,7 @@ protected function createEmbedViaData($data, $name = null) */ protected function normalizeEmail($email) { - if (is_array($email) || $email instanceof Traversable) { + if (is_array($email) || $email instanceof \Traversable) { $emails = []; foreach ($email as $k => $v) { diff --git a/Library/Phalcon/Mvc/Model/EagerLoading/Loader.php b/Library/Phalcon/Mvc/Model/EagerLoading/Loader.php index 590ac2aa9..73cfab379 100644 --- a/Library/Phalcon/Mvc/Model/EagerLoading/Loader.php +++ b/Library/Phalcon/Mvc/Model/EagerLoading/Loader.php @@ -1,12 +1,9 @@ newInstanceArgs( func_get_args() @@ -161,7 +158,7 @@ public static function fromModel(ModelInterface $subject) */ public static function fromArray(array $subject) { - $reflection = new ReflectionClass(__CLASS__); + $reflection = new \ReflectionClass(__CLASS__); $instance = $reflection->newInstanceArgs( func_get_args() @@ -179,7 +176,7 @@ public static function fromArray(array $subject) */ public static function fromResultset(Simple $subject) { - $reflection = new ReflectionClass(__CLASS__); + $reflection = new \ReflectionClass(__CLASS__); $instance = $reflection->newInstanceArgs( func_get_args() @@ -214,13 +211,13 @@ public function getSubject() * Parses the arguments that will be resolved to Relation instances * * @param array $arguments - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @return array */ private static function parseArguments(array $arguments) { if (empty($arguments)) { - throw new InvalidArgumentException('Arguments can not be empty'); + throw new \InvalidArgumentException('Arguments can not be empty'); } $relations = []; @@ -244,7 +241,7 @@ private static function parseArguments(array $arguments) } if (empty($relations)) { - throw new InvalidArgumentException; + throw new \InvalidArgumentException; } return $relations; @@ -258,7 +255,7 @@ private static function parseArguments(array $arguments) public function addEagerLoad($relationAlias, $constraints = null) { if (!is_string($relationAlias)) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( sprintf( '$relationAlias expects to be a string, `%s` given', gettype($relationAlias) @@ -267,7 +264,7 @@ public function addEagerLoad($relationAlias, $constraints = null) } if ($constraints !== null && !is_callable($constraints)) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( sprintf( '$constraints expects to be a callable, `%s` given', gettype($constraints) @@ -283,7 +280,7 @@ public function addEagerLoad($relationAlias, $constraints = null) /** * Resolves the relations * - * @throws RuntimeException + * @throws \RuntimeException * @return EagerLoad[] */ private function buildTree() @@ -331,7 +328,7 @@ private function buildTree() $relation = $mM->getRelationByAlias($parentClassName, $alias); if (!$relation instanceof Relation) { - throw new RuntimeException( + throw new \RuntimeException( sprintf( 'There is no defined relation for the model `%s` using alias `%s`', $parentClassName, @@ -351,7 +348,7 @@ private function buildTree() $relType !== Relation::HAS_ONE && $relType !== Relation::HAS_MANY && $relType !== Relation::HAS_MANY_THROUGH) { - throw new RuntimeException( + throw new \RuntimeException( sprintf( 'Unknown relation type `%s`', $relType @@ -360,7 +357,7 @@ private function buildTree() } if (is_array($relation->getFields()) || is_array($relation->getReferencedFields())) { - throw new RuntimeException( + throw new \RuntimeException( 'Relations with composite keys are not supported' ); } diff --git a/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php b/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php index bdf91851f..899040d39 100644 --- a/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php +++ b/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php @@ -1,22 +1,21 @@ * * @param mixed ...$arguments - * @return ModelInterface[] + * @return \Phalcon\Mvc\ModelInterface[] */ public static function with() { @@ -44,13 +41,13 @@ public static function with() unset($arguments[$lastArg]); if (isset($parameters['columns'])) { - throw new LogicException( + throw new \LogicException( 'Results from database must be full models, do not use `columns` key' ); } } } else { - throw new BadMethodCallException( + throw new \BadMethodCallException( sprintf('%s requires at least one argument', __METHOD__) ); } @@ -73,7 +70,7 @@ public static function with() * Same as EagerLoadingTrait::with() for a single record * * @param mixed ...$arguments - * @return false|ModelInterface + * @return false|\Phalcon\Mvc\ModelInterface */ public static function findFirstWith() { @@ -90,13 +87,13 @@ public static function findFirstWith() unset($arguments[$lastArg]); if (isset($parameters['columns'])) { - throw new LogicException( + throw new \LogicException( 'Results from database must be full models, do not use `columns` key' ); } } } else { - throw new BadMethodCallException( + throw new \BadMethodCallException( sprintf( '%s requires at least one argument', __METHOD__ diff --git a/Library/Phalcon/Mvc/View/Engine/Twig.php b/Library/Phalcon/Mvc/View/Engine/Twig.php index d5ae4c84b..512fdde5b 100644 --- a/Library/Phalcon/Mvc/View/Engine/Twig.php +++ b/Library/Phalcon/Mvc/View/Engine/Twig.php @@ -3,13 +3,8 @@ use Phalcon\DiInterface; use Phalcon\Mvc\View\Engine; -use Phalcon\Mvc\View\Engine\Twig\Environment; use Phalcon\Mvc\View\EngineInterface; use Phalcon\Mvc\ViewBaseInterface; -use Phalcon\Mvc\ViewInterface; -use Phalcon\Tag; -use Twig_Loader_Filesystem; -use Twig_SimpleFunction; /** * Phalcon\Mvc\View\Engine\Twig @@ -18,7 +13,7 @@ class Twig extends Engine implements EngineInterface { /** - * @var Environment + * @var \Phalcon\Mvc\View\Engine\Twig\Environment */ protected $twig; @@ -36,7 +31,7 @@ public function __construct( $options = [], $userFunctions = [] ) { - $loader = new Twig_Loader_Filesystem( + $loader = new \Twig_Loader_Filesystem( $view->getViewsDir() ); @@ -54,8 +49,8 @@ public function __construct( /** * Registers common function in Twig * - * @param ViewInterface $view - * @param DiInterface $di + * @param \Phalcon\Mvc\ViewInterface $view + * @param \Phalcon\DiInterface $di * @param array $userFunctions */ protected function registryFunctions($view, DiInterface $di, $userFunctions = []) @@ -63,168 +58,168 @@ protected function registryFunctions($view, DiInterface $di, $userFunctions = [] $options = ['is_safe' => ['html']]; $functions = [ - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'content', function () use ($view) { return $view->getContent(); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'partial', function ($partialPath, $params = null) use ($view) { return $view->partial($partialPath, $params); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'linkTo', function ($parameters, $text = null, $local = true) { - return Tag::linkTo($parameters, $text, $local); + return \Phalcon\Tag::linkTo($parameters, $text, $local); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'textField', function ($parameters) { - return Tag::textField($parameters); + return \Phalcon\Tag::textField($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'passwordField', function ($parameters) { - return Tag::passwordField($parameters); + return \Phalcon\Tag::passwordField($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'hiddenField', function ($parameters) { - return Tag::hiddenField($parameters); + return \Phalcon\Tag::hiddenField($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'fileField', function ($parameters) { - return Tag::fileField($parameters); + return \Phalcon\Tag::fileField($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'checkField', function ($parameters) { - return Tag::checkField($parameters); + return \Phalcon\Tag::checkField($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'radioField', function ($parameters) { - return Tag::radioField($parameters); + return \Phalcon\Tag::radioField($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'submitButton', function ($parameters) { - return Tag::submitButton($parameters); + return \Phalcon\Tag::submitButton($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'selectStatic', function ($parameters, $data = []) { - return Tag::selectStatic($parameters, $data); + return \Phalcon\Tag::selectStatic($parameters, $data); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'select', function ($parameters, $data = []) { - return Tag::select($parameters, $data); + return \Phalcon\Tag::select($parameters, $data); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'textArea', function ($parameters) { - return Tag::textArea($parameters); + return \Phalcon\Tag::textArea($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'form', function ($parameters = []) { - return Tag::form($parameters); + return \Phalcon\Tag::form($parameters); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'endForm', function () { - return Tag::endForm(); + return \Phalcon\Tag::endForm(); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'getTitle', function () { - return Tag::getTitle(); + return \Phalcon\Tag::getTitle(); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'stylesheetLink', function ($parameters = null, $local = true) { - return Tag::stylesheetLink($parameters, $local); + return \Phalcon\Tag::stylesheetLink($parameters, $local); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'javascriptInclude', function ($parameters = null, $local = true) { - return Tag::javascriptInclude($parameters, $local); + return \Phalcon\Tag::javascriptInclude($parameters, $local); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'image', function ($parameters = null, $local = true) { - return Tag::image($parameters, $local); + return \Phalcon\Tag::image($parameters, $local); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'friendlyTitle', function ($text, $separator = "-", $lc = true, $replace = null) { - return Tag::friendlyTitle($text, $separator, $lc, $replace); + return \Phalcon\Tag::friendlyTitle($text, $separator, $lc, $replace); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'getDocType', function () { - return Tag::getDocType(); + return \Phalcon\Tag::getDocType(); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'getSecurityToken', function () use ($di) { return $di->get("security")->getToken(); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'getSecurityTokenKey', function () use ($di) { return $di->get("security")->getTokenKey(); }, $options ), - new Twig_SimpleFunction( + new \Twig_SimpleFunction( 'url', function ($route) use ($di) { return $di->get("url")->get($route); @@ -278,7 +273,7 @@ public function render($path, $params, $mustClean = false) /** * Returns Twig environment object. * - * @return Environment + * @return \Phalcon\Mvc\View\Engine\Twig\Environment */ public function getTwig() { diff --git a/Library/Phalcon/Paginator/Pager.php b/Library/Phalcon/Paginator/Pager.php index fcf57fb3b..06de85473 100644 --- a/Library/Phalcon/Paginator/Pager.php +++ b/Library/Phalcon/Paginator/Pager.php @@ -19,28 +19,18 @@ namespace Phalcon\Paginator; -use ArrayIterator; -use Countable; -use Iterator; -use IteratorAggregate; -use Phalcon\Paginator\Pager\Layout; -use Phalcon\Paginator\Pager\Range; -use Phalcon\Paginator\Pager\Range\Sliding; -use RuntimeException; -use stdClass; - /** * \Phalcon\Paginator\Pager * Pager object is a navigation menu renderer based on doctrine1 pager object. * * @link https://github.com/doctrine/doctrine1/blob/master/lib/Doctrine/Pager.php */ -class Pager implements IteratorAggregate, Countable +class Pager implements \IteratorAggregate, \Countable { /** * Phalcon's paginate result. * - * @var stdClass + * @var \stdClass */ protected $paginateResult = null; @@ -69,7 +59,7 @@ class Pager implements IteratorAggregate, Countable * - layoutClass: Used with getLayout() method. Defaults to "Phalcon\Paginator\Pager\Layout". * - urlMask: Required with getLayout() method. * - * @param AdapterInterface $adapter Phalcon paginator adapter + * @param \Phalcon\Paginator\AdapterInterface $adapter Phalcon paginator adapter * @param array $options options array * */ @@ -154,17 +144,17 @@ public function getLastPage() /** * Returns the layout object. * - * @return Layout - * @throws RuntimeException in case options are not properly set + * @return \Phalcon\Paginator\Pager\Layout + * @throws \RuntimeException in case options are not properly set */ public function getLayout() { if (!array_key_exists('layoutClass', $this->options)) { - $this->options['layoutClass'] = Layout::class; + $this->options['layoutClass'] = \Phalcon\Paginator\Pager\Layout::class; } if (!array_key_exists('urlMask', $this->options)) { - throw new RuntimeException('You must provide option "urlMask"'); + throw new \RuntimeException('You must provide option "urlMask"'); } $range = null; @@ -172,7 +162,7 @@ public function getLayout() $rangeLength = $this->getRangeLength(); if (!class_exists($rangeClass)) { - throw new RuntimeException( + throw new \RuntimeException( sprintf( 'Unable to find range class "%s"', $rangeClass @@ -181,7 +171,7 @@ public function getLayout() } if (!class_exists($this->options['layoutClass'])) { - throw new RuntimeException( + throw new \RuntimeException( sprintf( 'Unable to find layout "%s"', $this->options['layoutClass'] @@ -205,7 +195,7 @@ public function getPagesInRange() { $rangeClass = $this->getRangeClass(); - /** @var Range $range */ + /** @var \Phalcon\Paginator\Pager\Range $range */ $range = new $rangeClass( $this, $this->getRangeLength() @@ -217,12 +207,12 @@ public function getPagesInRange() /** * {@inheritdoc} * - * @return ArrayIterator + * @return \ArrayIterator */ public function getIterator() { - if (!$this->paginateResult->items instanceof Iterator) { - return new ArrayIterator( + if (!$this->paginateResult->items instanceof \Iterator) { + return new \ArrayIterator( $this->paginateResult->items ); } @@ -250,7 +240,7 @@ public function count() protected function getRangeClass() { if (!array_key_exists('rangeClass', $this->options)) { - $this->options['rangeClass'] = Sliding::class; + $this->options['rangeClass'] = \Phalcon\Paginator\Pager\Range\Sliding::class; } return $this->options['rangeClass']; diff --git a/Library/Phalcon/Session/Adapter/Mongo.php b/Library/Phalcon/Session/Adapter/Mongo.php index b383aafe5..5e3824019 100644 --- a/Library/Phalcon/Session/Adapter/Mongo.php +++ b/Library/Phalcon/Session/Adapter/Mongo.php @@ -20,10 +20,6 @@ namespace Phalcon\Session\Adapter; -use DateInterval; -use DateTime; -use MongoCollection; -use MongoDate; use Phalcon\Session\Adapter; use Phalcon\Session\AdapterInterface; use Phalcon\Session\Exception; @@ -121,7 +117,7 @@ public function write($sessionId, $sessionData) $sessionData = [ '_id' => $sessionId, - 'modified' => new MongoDate(), + 'modified' => new \MongoDate(), 'data' => $sessionData, ]; @@ -156,15 +152,15 @@ public function destroy($sessionId = null) */ public function gc($maxLifetime) { - $minAge = new DateTime(); + $minAge = new \DateTime(); $minAge->sub( - new DateInterval( + new \DateInterval( 'PT' . $maxLifetime . 'S' ) ); - $minAgeMongo = new MongoDate( + $minAgeMongo = new \MongoDate( $minAge->getTimestamp() ); @@ -180,7 +176,7 @@ public function gc($maxLifetime) } /** - * @return MongoCollection + * @return \MongoCollection */ protected function getCollection() { diff --git a/Library/Phalcon/Test/Traits/FunctionalTestCase.php b/Library/Phalcon/Test/Traits/FunctionalTestCase.php index 3600ce759..09288beeb 100644 --- a/Library/Phalcon/Test/Traits/FunctionalTestCase.php +++ b/Library/Phalcon/Test/Traits/FunctionalTestCase.php @@ -22,7 +22,6 @@ use Phalcon\Mvc\Dispatcher as PhDispatcher; use Phalcon\Mvc\Application as PhApplication; use Phalcon\DiInterface; -use PHPUnit\Framework\ExpectationFailedException; trait FunctionalTestCase { @@ -98,7 +97,7 @@ protected function dispatch($url) * Assert that the last dispatched controller matches the given controller class name * * @param string $expected The expected controller name - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function assertController($expected) { @@ -107,7 +106,7 @@ public function assertController($expected) $actual = $dispatcher->getControllerName(); if ($actual != $expected) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( sprintf( 'Failed asserting Controller name "%s", actual Controller name is "%s"', $expected, @@ -123,7 +122,7 @@ public function assertController($expected) * Assert that the last dispatched action matches the given action name * * @param string $expected The expected action name - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function assertAction($expected) { @@ -132,7 +131,7 @@ public function assertAction($expected) $actual = $dispatcher->getActionName(); if ($actual != $expected) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( sprintf( 'Failed asserting Action name "%s", actual Action name is "%s"', $expected, @@ -151,7 +150,7 @@ public function assertAction($expected) * * * @param array $expected The expected headers - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function assertHeader(array $expected) { @@ -163,7 +162,7 @@ public function assertHeader(array $expected) $actualValue = $headers->get($expectedField); if ($actualValue != $expectedValue) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( sprintf( 'Failed asserting "%s" has a value of "%s", actual "%s" header value is "%s"', $expectedField, @@ -182,7 +181,7 @@ public function assertHeader(array $expected) * Asserts that the response code matches the given one * * @param string $expected the expected response code - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function assertResponseCode($expected) { @@ -198,7 +197,7 @@ public function assertResponseCode($expected) $actualValue = $headers->get('Status'); if (empty($actualValue) || stristr($actualValue, $expected) === false) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( sprintf( 'Failed asserting response code is "%s", actual response status is "%s"', $expected, @@ -213,17 +212,17 @@ public function assertResponseCode($expected) /** * Asserts that the dispatch is forwarded * - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function assertDispatchIsForwarded() { - /* @var $dispatcher PhDispatcher */ + /* @var $dispatcher \Phalcon\Mvc\Dispatcher */ $dispatcher = $this->di->getShared('dispatcher'); $actual = $dispatcher->wasForwarded(); if (!$actual) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( 'Failed asserting dispatch was forwarded' ); } @@ -235,7 +234,7 @@ public function assertDispatchIsForwarded() * Assert location redirect * * @param string $location - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function assertRedirectTo($location) { @@ -246,13 +245,13 @@ public function assertRedirectTo($location) $actualLocation = $headers->get('Location'); if (!$actualLocation) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( 'Failed asserting response caused a redirect' ); } if ($actualLocation !== $location) { - throw new ExpectationFailedException( + throw new \PHPUnit\Framework\ExpectationFailedException( sprintf( 'Failed asserting response redirects to "%s". It redirects to "%s".', $location, diff --git a/Library/Phalcon/Translate/Adapter/CsvMulti.php b/Library/Phalcon/Translate/Adapter/CsvMulti.php index a71a849fd..1ceac8ec5 100644 --- a/Library/Phalcon/Translate/Adapter/CsvMulti.php +++ b/Library/Phalcon/Translate/Adapter/CsvMulti.php @@ -2,10 +2,11 @@ namespace Phalcon\Translate\Adapter; -use ArrayAccess; +use Phalcon\Translate\AdapterInterface; +use Phalcon\Translate\Adapter\Csv; use Phalcon\Translate\Exception; -class CsvMulti extends Csv implements AdapterInterface, ArrayAccess +class CsvMulti extends Csv implements AdapterInterface, \ArrayAccess { /** * @var array @@ -43,7 +44,7 @@ private function _load($file, $length, $delimiter, $enclosure) "Error opening translation file '" . $file . "'" ); } - + $line = 0; $locales = []; @@ -68,10 +69,10 @@ private function _load($file, $length, $delimiter, $enclosure) } } } - + fclose($fileHandler); } - + /** * Sets locale information, according to one from the header row of the source csv * Set it to false for enabling the "no translation mode" @@ -93,30 +94,30 @@ public function setLocale($locale) return $this->locale = $locale; } - + /** * Returns the translation related to the given key and the previsouly set locale */ - public function query($index, $placeholders = null): string + public function query($index, $placeholders = null) { if (!$this->exists($index)) { throw new Exception("They key '{$index}' was not found."); } - + if ($this->locale === false) { // "no translation mode" $translation = $index; } else { $translation = $this->_translate[$this->locale][$index]; } - + return $this->replacePlaceholders($translation, $placeholders); } /** * Check whether is defined a translation key in the internal array */ - public function exists($index): bool + public function exists($index) { if (is_null($this->locale)) { throw new Exception('The locale must have been defined.'); @@ -127,7 +128,7 @@ public function exists($index): bool $this->getIndexes() ); } - + /** * Returns all the translation keys */ diff --git a/Library/Phalcon/Translate/Adapter/Database.php b/Library/Phalcon/Translate/Adapter/Database.php index 63d8b84f4..c5f528e89 100644 --- a/Library/Phalcon/Translate/Adapter/Database.php +++ b/Library/Phalcon/Translate/Adapter/Database.php @@ -20,13 +20,12 @@ namespace Phalcon\Translate\Adapter; -use ArrayAccess; use Phalcon\Db; use Phalcon\Translate\Adapter; use Phalcon\Translate\AdapterInterface; use Phalcon\Translate\Exception; -class Database extends Adapter implements AdapterInterface, ArrayAccess +class Database extends Adapter implements AdapterInterface, \ArrayAccess { /** * @var array @@ -49,7 +48,7 @@ class Database extends Adapter implements AdapterInterface, ArrayAccess * Class constructor. * * @param array $options - * @throws Exception + * @throws \Phalcon\Translate\Exception */ public function __construct(array $options) { @@ -76,7 +75,7 @@ public function __construct(array $options) ); $this->options = $options; - + parent::__construct($options); } diff --git a/Library/Phalcon/Translate/Adapter/Mongo.php b/Library/Phalcon/Translate/Adapter/Mongo.php index 40ecde882..6d05f2119 100644 --- a/Library/Phalcon/Translate/Adapter/Mongo.php +++ b/Library/Phalcon/Translate/Adapter/Mongo.php @@ -19,7 +19,6 @@ namespace Phalcon\Translate\Adapter; -use ArrayAccess; use Phalcon\Translate\Exception; use Phalcon\Mvc\CollectionInterface; use Phalcon\Translate\Adapter; @@ -35,7 +34,7 @@ * * @package Phalcon\Translate\Adapter */ -class Mongo extends Adapter implements AdapterInterface, ArrayAccess +class Mongo extends Adapter implements AdapterInterface, \ArrayAccess { protected $language; protected $collection; @@ -60,7 +59,7 @@ public function __construct($options) } $this->setLanguage($options['language']); - + parent::__construct($options); } diff --git a/Library/Phalcon/Translate/Adapter/Redis.php b/Library/Phalcon/Translate/Adapter/Redis.php index f11aff17e..81bf72251 100644 --- a/Library/Phalcon/Translate/Adapter/Redis.php +++ b/Library/Phalcon/Translate/Adapter/Redis.php @@ -44,7 +44,7 @@ class Redis extends Adapter implements AdapterInterface * Class constructor. * * @param array $options - * @throws Exception + * @throws \Phalcon\Translate\Exception */ public function __construct(array $options) { @@ -62,7 +62,7 @@ public function __construct(array $options) if (isset($options['levels'])) { $this->levels = $options['levels']; } - + parent::__construct($options); } @@ -99,7 +99,7 @@ public function query($translateKey, $placeholders = null) $value = isset($this->cache[$key]) && isset($this->cache[$key][$index]) ? $this->cache[$key][$index] : $translateKey; - + return $this->replacePlaceholders($value, $placeholders); } diff --git a/Library/Phalcon/Translate/Adapter/ResourceBundle.php b/Library/Phalcon/Translate/Adapter/ResourceBundle.php index 12c8ebef5..7d174c1bf 100644 --- a/Library/Phalcon/Translate/Adapter/ResourceBundle.php +++ b/Library/Phalcon/Translate/Adapter/ResourceBundle.php @@ -30,7 +30,7 @@ class ResourceBundle extends Adapter implements AdapterInterface * * @param array $options * - * @throws Exception + * @throws \Phalcon\Translate\Exception */ public function __construct($options) { @@ -61,7 +61,7 @@ public function __construct($options) $this->options['bundle'], $this->fallback ); - + parent::__construct($options); } diff --git a/Library/Phalcon/Translate/Interpolator/Intl.php b/Library/Phalcon/Translate/Interpolator/Intl.php index c804368a0..af28f5e33 100644 --- a/Library/Phalcon/Translate/Interpolator/Intl.php +++ b/Library/Phalcon/Translate/Interpolator/Intl.php @@ -2,6 +2,7 @@ namespace Phalcon\Translate\Interpolator; +use Phalcon\Translate\InterpolatorInterface; use Phalcon\Translate\Exception; use MessageFormatter; use IntlException; @@ -9,18 +10,18 @@ class Intl implements InterpolatorInterface { private $locale; - + public function __construct($locale) { $this->locale = $locale; } - + /** * Replaces placeholders by the values passed * Use the MessageFormatter class, * See http://php.net/manual/en/class.messageformatter.php */ - public function replacePlaceholders(string $translation, array $placeholders = null): string + public function replacePlaceholders($translation, $placeholders = null) { if (is_array($placeholders) && count($placeholders)) { try { @@ -40,7 +41,7 @@ public function replacePlaceholders(string $translation, array $placeholders = n ); } } - + $translation = $fmt->format($placeholders); if ($translation === false) { throw new Exception($fmt->getErrorMessage(), $fmt->getErrorCode()); diff --git a/Library/Phalcon/Validation/Validator/AlphaNamesValidator.php b/Library/Phalcon/Validation/Validator/AlphaNamesValidator.php index 048988dd1..c63e0b352 100644 --- a/Library/Phalcon/Validation/Validator/AlphaNamesValidator.php +++ b/Library/Phalcon/Validation/Validator/AlphaNamesValidator.php @@ -3,10 +3,11 @@ namespace Phalcon\Validation\Validator; use Phalcon\Validation; -use Phalcon\Messages\Message; -use Phalcon\Validation\AbstractValidator; +use Phalcon\Validation\Message; +use Phalcon\Validation\Validator; +use Phalcon\Validation\ValidatorInterface; -class AlphaNamesValidator extends AbstractValidator +class AlphaNamesValidator extends Validator implements ValidatorInterface { /** * Executes the validation. Allowed options: @@ -19,7 +20,7 @@ class AlphaNamesValidator extends AbstractValidator * * @return boolean */ - public function validate(Validation $validator, $attribute): bool + public function validate(Validation $validator, $attribute) { $value = $validator->getValue($attribute); diff --git a/Library/Phalcon/Validation/Validator/AlphaNumericValidator.php b/Library/Phalcon/Validation/Validator/AlphaNumericValidator.php index 968194d8f..50c064f4b 100644 --- a/Library/Phalcon/Validation/Validator/AlphaNumericValidator.php +++ b/Library/Phalcon/Validation/Validator/AlphaNumericValidator.php @@ -3,10 +3,11 @@ namespace Phalcon\Validation\Validator; use Phalcon\Validation; -use Phalcon\Messages\Message; -use Phalcon\Validation\AbstractValidator; +use Phalcon\Validation\Message; +use Phalcon\Validation\Validator; +use Phalcon\Validation\ValidatorInterface; -class AlphaNumericValidator extends AbstractValidator +class AlphaNumericValidator extends Validator implements ValidatorInterface { /** * Executes the validation. Allowed options: @@ -20,7 +21,7 @@ class AlphaNumericValidator extends AbstractValidator * * @return boolean */ - public function validate(Validation $validator, $attribute): bool + public function validate(Validation $validator, $attribute) { $value = $validator->getValue($attribute); diff --git a/Library/Phalcon/Validation/Validator/ArrayInclusionIn.php b/Library/Phalcon/Validation/Validator/ArrayInclusionIn.php index 9b2327be3..89667ada9 100644 --- a/Library/Phalcon/Validation/Validator/ArrayInclusionIn.php +++ b/Library/Phalcon/Validation/Validator/ArrayInclusionIn.php @@ -2,23 +2,23 @@ namespace Phalcon\Validation\Validator; -use Phalcon\Validation; -use Phalcon\Messages\Message; -use Phalcon\Validation\AbstractValidator; +use Phalcon\Validation\Message; +use Phalcon\Validation\Validator; +use Phalcon\Validation\ValidatorInterface; -class ArrayInclusionIn extends AbstractValidator +class ArrayInclusionIn extends Validator implements ValidatorInterface { /** * Executes the validation * - * @param Validation $validation + * @param \Phalcon\Validation $validation * @param string $attribute * @return bool * * @throws \Exception */ - public function validate(Validation $validation, $attribute): bool + public function validate(\Phalcon\Validation $validation, $attribute) { $array = $validation->getValue($attribute); $domain = $this->getOption('domain'); diff --git a/Library/Phalcon/Validation/Validator/CardNumber.php b/Library/Phalcon/Validation/Validator/CardNumber.php index 4d4112622..69a31ef5b 100644 --- a/Library/Phalcon/Validation/Validator/CardNumber.php +++ b/Library/Phalcon/Validation/Validator/CardNumber.php @@ -20,8 +20,8 @@ namespace Phalcon\Validation\Validator; use Phalcon\Validation; -use Phalcon\Messages\Message; -use Phalcon\Validation\AbstractValidator; +use Phalcon\Validation\Message; +use Phalcon\Validation\Validator; use Phalcon\Validation\Exception as ValidationException; /** @@ -38,7 +38,7 @@ * ])); * */ -class CardNumber extends AbstractValidator +class CardNumber extends Validator { const AMERICAN_EXPRESS = 0; // 34, 37 const MASTERCARD = 1; // 51-55 @@ -53,7 +53,7 @@ class CardNumber extends AbstractValidator * @return bool * @throws Exception */ - public function validate(Validation $validation, $attribute): bool + public function validate(Validation $validation, $attribute) { $value = preg_replace( '/[^\d]/', @@ -71,17 +71,17 @@ public function validate(Validation $validation, $attribute): bool $issuer = substr($value, 0, 2); $result = (true === in_array($issuer, [34, 37])); break; - + case CardNumber::MASTERCARD: $issuer = substr($value, 0, 2); $result = (true === in_array($issuer, [51, 52, 53, 54, 55])); break; - + case CardNumber::VISA: $issuer = $value[0]; $result = ($issuer == 4); break; - + default: throw new ValidationException('Incorrect type specifier'); } diff --git a/Library/Phalcon/Validation/Validator/NumericValidator.php b/Library/Phalcon/Validation/Validator/NumericValidator.php index 2e2c100b7..088d33036 100644 --- a/Library/Phalcon/Validation/Validator/NumericValidator.php +++ b/Library/Phalcon/Validation/Validator/NumericValidator.php @@ -3,11 +3,11 @@ namespace Phalcon\Validation\Validator; use Phalcon\Validation; -use Phalcon\Messages\Message; -use Phalcon\Validation\AbstractValidator; +use Phalcon\Validation\Message; +use Phalcon\Validation\Validator; use Phalcon\Validation\ValidatorInterface; -class NumericValidator extends AbstractValidator implements ValidatorInterface +class NumericValidator extends Validator implements ValidatorInterface { /** * Executes the validation. Allowed options: @@ -20,7 +20,7 @@ class NumericValidator extends AbstractValidator implements ValidatorInterface * * @return boolean */ - public function validate(Validation $validator, $attribute): bool + public function validate(Validation $validator, $attribute) { $value = $validator->getValue($attribute); diff --git a/composer.json b/composer.json index d9c1ad1dd..fd6040263 100644 --- a/composer.json +++ b/composer.json @@ -30,21 +30,21 @@ "email": "support@phalconphp.com" }, "require": { - "php": ">=7.2", - "ext-phalcon": "*" + "php": ">=5.5", + "ext-phalcon": "~3.3" }, "require-dev": { - "phpdocumentor/reflection-docblock": "^4.3.1", - "phpunit/phpunit": "^7.0", + "phpdocumentor/reflection-docblock": "2.0.4", + "phpunit/phpunit": "^4.8", "squizlabs/php_codesniffer": "^2.9", - "codeception/codeception": "^3.0", - "codeception/mockery-module": "^0.3.0", - "codeception/specify": "^1.1", - "codeception/verify": "^1.0.0", - "codeception/aerospike-module": "^1", - "vlucas/phpdotenv": "^3.4.0", + "codeception/codeception": "^2.5", + "codeception/mockery-module": "0.2.2", + "codeception/aerospike-module": "^1.0", + "codeception/specify": "^0.4", + "codeception/verify": "^0.3", + "vlucas/phpdotenv": "^2.4", "phalcon/dd": "^1.1", - "doctrine/instantiator": "^1.2.0" + "doctrine/instantiator": "1.0.5" }, "suggest": { "ext-aerospike": "*", diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 963cc32a8..96f62c5f5 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -2,7 +2,7 @@ require_once realpath(dirname(__DIR__)) . '/vendor/autoload.php'; -(Dotenv\Dotenv::create(realpath(__DIR__)))->load(); +(new Dotenv\Dotenv(realpath(__DIR__)))->load(); require_once '_support/functions.php'; @@ -22,8 +22,6 @@ ini_set('xdebug.var_display_max_depth', 4); } -ini_set('apc.enable_cli', 'on'); - clearstatcache(); $root = realpath(__DIR__) . DIRECTORY_SEPARATOR; diff --git a/tests/unit/Validation/Validator/IbanTest.php b/tests/unit/Validation/Validator/IbanTest.php index a59dbe370..92fcc359d 100644 --- a/tests/unit/Validation/Validator/IbanTest.php +++ b/tests/unit/Validation/Validator/IbanTest.php @@ -41,18 +41,15 @@ public function shouldValidateIbanCodeWithSetCountryCode($countryCode, $code) { $validation = new Validation(); - $key = 'test'; - $validation->add( - $key, + 'test', new Iban() ); $validators = $validation->getValidators(); - $validator = $validators[$key]; - - $validator = $validator[0]; + $validator = $validators[0]; + $validator = $validator[1]; $validator->setCountryCode($countryCode); diff --git a/tests/unit5x/Validation/Validator/MongoIdTest.php b/tests/unit5x/Validation/Validator/MongoIdTest.php new file mode 100644 index 000000000..12b9b9f47 --- /dev/null +++ b/tests/unit5x/Validation/Validator/MongoIdTest.php @@ -0,0 +1,178 @@ + + * @package Phalcon\Test\Validation\Validator + * @group Validation + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file docs/LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class MongoIdTest extends Test +{ + const MIN_PECL_VERSION = '1.5.2'; + + /** + * UnitTester Object + * @var UnitTester + */ + protected $tester; + + /** + * @var MongoId + */ + private $testable; + + /** + * @var Validation + */ + private $validation; + + /** + * executed before each test + */ + protected function _before() + { + if (!extension_loaded('mongo')) { + $this->markTestSkipped( + 'The Mongo extension is not available.' + ); + } + + $ext = new ReflectionExtension('mongo'); + + if (!version_compare($ext->getVersion(), self::MIN_PECL_VERSION, '>=')) { + $this->markTestSkipped( + sprintf( + "Your mongo extension version isn't compatible with Incubator, download the latest at: %s", + 'https://docs.mongodb.org/ecosystem/drivers/php/' + ) + ); + } + + $this->testable = new MongoId(); + $this->validation = new Validation(); + } + + /** + * executed after each test + */ + protected function _after() + { + } + + public function testInvalidMongoIdValue() + { + $array = [ + 'id' => 123, + ]; + + $this->validation->add( + 'id', + $this->testable + ); + + $messages = $this->validation->validate($array); + + $this->assertCount( + 1, + $messages + ); + + $this->assertEquals( + 'MongoId is not valid', + $messages[0]->getMessage() + ); + + $this->assertEquals( + 'MongoId', + $messages[0]->getType() + ); + } + + public function testValidMongoIdValue() + { + $array = [ + 'id' => '561824e063e702bc1900002a', + ]; + + $this->validation->add( + 'id', + $this->testable + ); + + $messages = $this->validation->validate($array); + + $this->assertCount( + 0, + $messages + ); + } + + public function testEmptyMongoIdValue() + { + $array = [ + 'id' => '', + ]; + + $this->validation->add( + 'id', + $this->testable + ); + + $messages = $this->validation->validate($array); + + $this->assertCount( + 1, + $messages + ); + + $this->assertEquals( + 'MongoId is not valid', + $messages[0]->getMessage() + ); + + $this->assertEquals( + 'MongoId', + $messages[0]->getType() + ); + } + + public function testEmptyMongoIdValueWithAllowEmptyOption() + { + $array = [ + 'id' => '', + ]; + + $this->testable->setOption('allowEmpty', true); + + $this->validation->add( + 'id', + $this->testable + ); + + $messages = $this->validation->validate($array); + + $this->assertCount( + 0, + $messages + ); + } +}