diff --git a/.travis.yml b/.travis.yml index 3b4557d8d..33a121a3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,7 +75,7 @@ script: - vendor/bin/codecept run unit -v - vendor/bin/codecept run functional -v - vendor/bin/codecept run console -v - - '[[ "$PHP_MAJOR" == "5" ]] || vendor/bin/phpstan analyse -l 1 -c phpstan.neon scripts -vvv' + - '[[ "$PHP_MAJOR" == "5" ]] || vendor/bin/phpstan analyse -l 5 -c phpstan.neon scripts -vvv' notifications: email: diff --git a/README.md b/README.md index 6da6c4d33..a247fea38 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ This command should display something similar to: ```sh $ phalcon --help -Phalcon DevTools (3.2.7) +Phalcon DevTools (3.2.8) Help: Lists the commands available in Phalcon devtools diff --git a/scripts/Phalcon/Builder/Controller.php b/scripts/Phalcon/Builder/Controller.php index 091b331ec..46ac275be 100644 --- a/scripts/Phalcon/Builder/Controller.php +++ b/scripts/Phalcon/Builder/Controller.php @@ -71,11 +71,11 @@ public function build() if (!$controllersDir = $this->options->get('controllersDir')) { $config = $this->getConfig(); - if (!isset($config->application->controllersDir)) { + if (empty($config->path('application.controllersDir'))) { throw new BuilderException('Please specify a controller directory.'); } - $controllersDir = $config->application->controllersDir; + $controllersDir = $config->path('application.controllersDir'); } if (!$this->options->contains('name')) { diff --git a/scripts/Phalcon/Builder/Project.php b/scripts/Phalcon/Builder/Project.php index d6ea439a0..6ddf4c346 100644 --- a/scripts/Phalcon/Builder/Project.php +++ b/scripts/Phalcon/Builder/Project.php @@ -43,7 +43,7 @@ class Project extends Component /** * Current Project Type - * @var null + * @var string */ private $currentType = self::TYPE_SIMPLE; diff --git a/scripts/Phalcon/Builder/Scaffold.php b/scripts/Phalcon/Builder/Scaffold.php index ce6da020b..7503a04a5 100644 --- a/scripts/Phalcon/Builder/Scaffold.php +++ b/scripts/Phalcon/Builder/Scaffold.php @@ -91,23 +91,23 @@ public function build() $name = $this->options->get('name'); $config = $this->getConfig(); - if (!isset($config->database->adapter)) { + if (empty($config->path('database.adapter'))) { throw new BuilderException('Adapter was not found in the config. Please specify a config variable [database][adapter].'); } $adapter = 'Mysql'; - if (isset($config->database->adapter)) { - $adapter = ucfirst($config->database->adapter); + if (!empty($config->path('database.adapter'))) { + $adapter = ucfirst($config->path('database.adapter')); $this->isSupportedAdapter($adapter); } $di = new FactoryDefault(); $di->set('db', function () use ($adapter, $config) { - if (is_object($config->database)) { - $configArray = $config->database->toArray(); + if (is_object($config->path('database'))) { + $configArray = $config->path('database')->toArray(); } else { - $configArray = $config->database; + $configArray = $config->path('database'); } $adapterName = 'Phalcon\Db\Adapter\Pdo\\' . $adapter; @@ -116,32 +116,32 @@ public function build() return new $adapterName($configArray); }); - if (!isset($config->application->modelsDir)) { + if (empty($config->path('application.modelsDir'))) { throw new BuilderException('The builder is unable to find the models directory.'); } - $modelPath = $config->application->modelsDir; + $modelPath = $config->path('application.modelsDir'); if (false == $this->isAbsolutePath($modelPath)) { - $modelPath = $this->path->getRootPath($config->application->modelsDir); + $modelPath = $this->path->getRootPath($config->path('application.modelsDir')); } $this->options->offsetSet('modelsDir', rtrim($modelPath, '\\/') . DIRECTORY_SEPARATOR); - if (!isset($config->application->controllersDir)) { + if (empty($config->path('application.controllersDir'))) { throw new BuilderException('The builder is unable to find the controllers directory.'); } - $controllerPath = $config->application->controllersDir; + $controllerPath = $config->path('application.controllersDir'); if (false == $this->isAbsolutePath($controllerPath)) { - $controllerPath = $this->path->getRootPath($config->application->controllersDir); + $controllerPath = $this->path->getRootPath($config->path('application.controllersDir')); } $this->options->offsetSet('controllersDir', rtrim($controllerPath, '\\/') . DIRECTORY_SEPARATOR); - if (!isset($config->application->viewsDir)) { + if (empty($config->path('application.viewsDir'))) { throw new BuilderException('The builder is unable to find the views directory.'); } - $viewPath = $config->application->viewsDir; + $viewPath = $config->path('application.viewsDir'); if (false == $this->isAbsolutePath($viewPath)) { - $viewPath = $this->path->getRootPath($config->application->viewsDir); + $viewPath = $this->path->getRootPath($config->path('application.viewsDir')); } $this->options->offsetSet('viewsDir', $viewPath); @@ -418,14 +418,14 @@ private function _makeFieldVolt($attribute, $dataType, $relationField, $selectDe */ private function _makeFields($action) { - $entity = $this->options->entity; - $relationField = $this->options->relationField; - $autocompleteFields = $this->options->autocompleteFields; - $selectDefinition = $this->options->selectDefinition->toArray(); - $identityField = $this->options->identityField; + $entity = $this->options->get('entity'); + $relationField = $this->options->get('relationField'); + $autocompleteFields = $this->options->get('autocompleteFields'); + $selectDefinition = $this->options->get('selectDefinition')->toArray(); + $identityField = $this->options->get('identityField'); $code = ''; - foreach ($this->options->dataTypes as $attribute => $dataType) { + foreach ($this->options->get('dataTypes') as $attribute => $dataType) { if (($action == 'new' || $action == 'edit') && $attribute == $identityField) { continue; } @@ -443,14 +443,14 @@ private function _makeFields($action) */ private function _makeFieldsVolt($action) { - $entity = $this->options->entity; - $relationField = $this->options->relationField; - $autocompleteFields = $this->options->autocompleteFields; - $selectDefinition = $this->options->selectDefinition->toArray(); - $identityField = $this->options->identityField; + $entity = $this->options->get('entity'); + $relationField = $this->options->get('relationField'); + $autocompleteFields = $this->options->get('autocompleteFields'); + $selectDefinition = $this->options->get('selectDefinition')->toArray(); + $identityField = $this->options->get('identityField'); $code = ''; - foreach ($this->options->dataTypes as $attribute => $dataType) { + foreach ($this->options->get('dataTypes') as $attribute => $dataType) { if (($action == 'new' || $action == 'edit') && $attribute == $identityField) { continue; } @@ -545,14 +545,14 @@ private function _makeController() private function _makeLayouts() { // Make Layouts dir - $dirPathLayouts = $this->options->viewsDir . 'layouts'; + $dirPathLayouts = $this->options->get('viewsDir') . 'layouts'; //If dir doesn't exist we make it if (is_dir($dirPathLayouts) == false) { mkdir($dirPathLayouts, 0777, true); } - $fileName = $this->options->fileName; + $fileName = $this->options->get('fileName'); $viewPath = $dirPathLayouts . DIRECTORY_SEPARATOR . $fileName . '.phtml'; if (!file_exists($viewPath) || $this->options->contains('force')) { @@ -586,14 +586,14 @@ private function _makeLayouts() private function _makeLayoutsVolt() { // Make Layouts dir - $dirPathLayouts = $this->options->viewsDir . 'layouts'; + $dirPathLayouts = $this->options->get('viewsDir') . 'layouts'; // If not exists dir; we make it if (is_dir($dirPathLayouts) == false) { mkdir($dirPathLayouts, 0777, true); } - $fileName = Text::uncamelize($this->options->fileName); + $fileName = Text::uncamelize($this->options->get('fileName')); $viewPath = $dirPathLayouts . DIRECTORY_SEPARATOR . $fileName . '.volt'; if (!file_exists($viewPath || $this->options->contains('force'))) { @@ -627,7 +627,7 @@ private function _makeLayoutsVolt() */ private function makeView($type) { - $dirPath = $this->options->viewsDir . $this->options->fileName; + $dirPath = $this->options->get('viewsDir') . $this->options->get('fileName'); if (is_dir($dirPath) == false) { mkdir($dirPath); } @@ -639,14 +639,14 @@ private function makeView($type) } } - $templatePath = $this->options->templatePath . '/scaffold/no-forms/views/' .$type. '.phtml'; + $templatePath = $this->options->get('templatePath') . '/scaffold/no-forms/views/' .$type. '.phtml'; if (!file_exists($templatePath)) { throw new BuilderException(sprintf('Template "%s" does not exist', $templatePath)); } $code = file_get_contents($templatePath); - $code = str_replace('$plural$', $this->options->plural, $code); + $code = str_replace('$plural$', $this->options->get('plural'), $code); $code = str_replace('$captureFields$', self::_makeFields($type), $code); if ($this->isConsole()) { @@ -664,7 +664,7 @@ private function makeView($type) */ private function makeViewVolt($type) { - $dirPath = $this->options->viewsDir . $this->options->fileName; + $dirPath = $this->options->get('viewsDir') . $this->options->get('fileName'); if (is_dir($dirPath) == false) { mkdir($dirPath, 0777, true); } @@ -676,14 +676,14 @@ private function makeViewVolt($type) } } - $templatePath = $this->options->templatePath . '/scaffold/no-forms/views/' . $type . '.volt'; + $templatePath = $this->options->get('templatePath') . '/scaffold/no-forms/views/' . $type . '.volt'; if (!file_exists($templatePath)) { throw new BuilderException(sprintf('Template "%s" does not exist.', $templatePath)); } $code = file_get_contents($templatePath); - $code = str_replace('$plural$', $this->options->plural, $code); + $code = str_replace('$plural$', $this->options->get('plural'), $code); $code = str_replace('$captureFields$', self::_makeFieldsVolt($type), $code); if ($this->isConsole()) { @@ -701,7 +701,7 @@ private function makeViewVolt($type) */ private function _makeViewSearch() { - $dirPath = $this->options->viewsDir . $this->options->fileName; + $dirPath = $this->options->get('viewsDir') . $this->options->get('fileName'); if (is_dir($dirPath) == false) { mkdir($dirPath); } @@ -711,44 +711,44 @@ private function _makeViewSearch() return; } - $templatePath = $this->options->templatePath . '/scaffold/no-forms/views/search.phtml'; + $templatePath = $this->options->get('templatePath') . '/scaffold/no-forms/views/search.phtml'; if (!file_exists($templatePath)) { throw new BuilderException(sprintf('Template "%s" does not exist', $templatePath)); } $headerCode = ''; - foreach ($this->options->attributes as $attribute) { + foreach ($this->options->get('attributes') as $attribute) { $headerCode .= "\t\t\t" . '' . $this->_getPossibleLabel($attribute) . '' . PHP_EOL; } $rowCode = ''; - $this->options->offsetSet('allReferences', array_merge($this->options->autocompleteFields->toArray(), $this->options->selectDefinition->toArray())); - foreach ($this->options->dataTypes as $fieldName => $dataType) { + $this->options->offsetSet('allReferences', array_merge($this->options->get('autocompleteFields')->toArray(), $this->options->get('selectDefinition')->toArray())); + foreach ($this->options->get('dataTypes') as $fieldName => $dataType) { $rowCode .= "\t\t\t" . 'options->allReferences[$fieldName])) { - if ($this->options->genSettersGetters) { - $rowCode .= '$' . Utils::lowerCamelizeWithDelimiter($this->options->singular, '-', true) . '->get' . Text::camelize($fieldName) . '()'; + if (!isset($this->options->get('allReferences')[$fieldName])) { + if ($this->options->get('genSettersGetters')) { + $rowCode .= '$' . Utils::lowerCamelizeWithDelimiter($this->options->get('singular'), '-', true) . '->get' . Text::camelize($fieldName) . '()'; } else { - $rowCode .= '$' . $this->options->singular . '->' . $fieldName; + $rowCode .= '$' . $this->options->get('singular') . '->' . $fieldName; } } else { - $detailField = ucfirst($this->options->allReferences[$fieldName]['detail']); - $rowCode .= '$' . $this->options->singular . '->get' . $this->options->allReferences[$fieldName]['tableName'] . '()->get' . $detailField . '()'; + $detailField = ucfirst($this->options->get('allReferences')[$fieldName]['detail']); + $rowCode .= '$' . $this->options->get('singular') . '->get' . $this->options->get('allReferences')[$fieldName]['tableName'] . '()->get' . $detailField . '()'; } $rowCode .= ' ?>' . PHP_EOL; } - $idField = $this->options->attributes[0]; + $idField = $this->options->get('attributes')[0]; if ($this->options->contains('genSettersGetters')) { - $idField = 'get' . Text::camelize($this->options->attributes[0]) . '()'; + $idField = 'get' . Text::camelize($this->options->get('attributes')[0]) . '()'; } $code = file_get_contents($templatePath); - $code = str_replace('$plural$', $this->options->plural, $code); + $code = str_replace('$plural$', $this->options->get('plural'), $code); $code = str_replace('$headerColumns$', $headerCode, $code); $code = str_replace('$rowColumns$', $rowCode, $code); - $code = str_replace('$singularVar$', '$' . Utils::lowerCamelizeWithDelimiter($this->options->singular, '-', true), $code); + $code = str_replace('$singularVar$', '$' . Utils::lowerCamelizeWithDelimiter($this->options->get('singular'), '-', true), $code); $code = str_replace('$pk$', $idField, $code); if ($this->isConsole()) { @@ -764,7 +764,7 @@ private function _makeViewSearch() */ private function _makeViewSearchVolt() { - $dirPath = $this->options->viewsDir . $this->options->fileName; + $dirPath = $this->options->get('viewsDir') . $this->options->get('fileName'); if (is_dir($dirPath) == false) { mkdir($dirPath); } @@ -776,44 +776,44 @@ private function _makeViewSearchVolt() } } - $templatePath = $this->options->templatePath . '/scaffold/no-forms/views/search.volt'; + $templatePath = $this->options->get('templatePath') . '/scaffold/no-forms/views/search.volt'; if (!file_exists($templatePath)) { throw new BuilderException("Template '" . $templatePath . "' does not exist"); } $headerCode = ''; - foreach ($this->options->attributes as $attribute) { + foreach ($this->options->get('attributes') as $attribute) { $headerCode .= "\t\t\t" . '' . $this->_getPossibleLabel($attribute) . '' . PHP_EOL; } $rowCode = ''; - $this->options->offsetSet('allReferences', array_merge($this->options->autocompleteFields->toArray(), $this->options->selectDefinition->toArray())); - foreach ($this->options->dataTypes as $fieldName => $dataType) { + $this->options->offsetSet('allReferences', array_merge($this->options->get('autocompleteFields')->toArray(), $this->options->get('selectDefinition')->toArray())); + foreach ($this->options->get('dataTypes') as $fieldName => $dataType) { $rowCode .= "\t\t\t" . '{{ '; - if (!isset($this->options->allReferences[$fieldName])) { + if (!isset($this->options->get('allReferences')[$fieldName])) { if ($this->options->contains('genSettersGetters')) { - $rowCode .= Utils::lowerCamelizeWithDelimiter($this->options->singular, '-', true) . '.get' . Text::camelize($fieldName) . '()'; + $rowCode .= Utils::lowerCamelizeWithDelimiter($this->options->get('singular'), '-', true) . '.get' . Text::camelize($fieldName) . '()'; } else { - $rowCode .= $this->options->singular . '.' . $fieldName; + $rowCode .= $this->options->get('singular') . '.' . $fieldName; } } else { - $detailField = ucfirst($this->options->allReferences[$fieldName]['detail']); - $rowCode .= $this->options->singular . '.get' . $this->options->allReferences[$fieldName]['tableName'] . '().get' . $detailField . '()'; + $detailField = ucfirst($this->options->get('allReferences')[$fieldName]['detail']); + $rowCode .= $this->options->get('singular') . '.get' . $this->options->get('allReferences')[$fieldName]['tableName'] . '().get' . $detailField . '()'; } $rowCode .= ' }}' . PHP_EOL; } - $idField = $this->options->attributes[0]; + $idField = $this->options->get('attributes')[0]; if ($this->options->contains('genSettersGetters')) { - $idField = 'get' . Text::camelize($this->options->attributes[0]) . '()'; + $idField = 'get' . Text::camelize($this->options->get('attributes')[0]) . '()'; } $code = file_get_contents($templatePath); - $code = str_replace('$plural$', $this->options->plural, $code); + $code = str_replace('$plural$', $this->options->get('plural'), $code); $code = str_replace('$headerColumns$', $headerCode, $code); $code = str_replace('$rowColumns$', $rowCode, $code); - $code = str_replace('$singularVar$', Utils::lowerCamelizeWithDelimiter($this->options->singular, '-', true), $code); + $code = str_replace('$singularVar$', Utils::lowerCamelizeWithDelimiter($this->options->get('singular'), '-', true), $code); $code = str_replace('$pk$', $idField, $code); if ($this->isConsole()) { diff --git a/scripts/Phalcon/Commands/Command.php b/scripts/Phalcon/Commands/Command.php index 6f63af53e..e155d23c2 100644 --- a/scripts/Phalcon/Commands/Command.php +++ b/scripts/Phalcon/Commands/Command.php @@ -422,7 +422,7 @@ public function getOption($option, $filters = null, $defaultValue = null) /** * Indicates whether the script was a particular option. * - * @param string $option + * @param string | string[] $option * @return boolean */ public function isReceivedOption($option) @@ -458,7 +458,7 @@ protected function filter($paramValue, $filters) /** * Gets the last parameter is not associated with any parameter name. * - * @return string + * @return string | bool */ public function getLastUnNamedParam() { diff --git a/scripts/Phalcon/Db/Adapter/Pdo/PostgresqlExtended.php b/scripts/Phalcon/Db/Adapter/Pdo/PostgresqlExtended.php index 70889bc22..8d9dad0d7 100644 --- a/scripts/Phalcon/Db/Adapter/Pdo/PostgresqlExtended.php +++ b/scripts/Phalcon/Db/Adapter/Pdo/PostgresqlExtended.php @@ -37,7 +37,7 @@ class PostgresqlExtended extends Postgresql * * @param string $table * @param string $schema - * @return Reference + * @return ReferenceInterface[] * */ public function describeReferences($table, $schema = NULL) diff --git a/scripts/Phalcon/Devtools/Version.php b/scripts/Phalcon/Devtools/Version.php index da1a7e876..03a0c3dac 100644 --- a/scripts/Phalcon/Devtools/Version.php +++ b/scripts/Phalcon/Devtools/Version.php @@ -39,6 +39,6 @@ class Version extends PhVersion */ protected static function _getVersion() { - return [3, 2, 7, 4, 0]; + return [3, 2, 8, 4, 0]; } } diff --git a/scripts/Phalcon/Error/ErrorHandler.php b/scripts/Phalcon/Error/ErrorHandler.php index 6dcbe9325..bfd584d53 100644 --- a/scripts/Phalcon/Error/ErrorHandler.php +++ b/scripts/Phalcon/Error/ErrorHandler.php @@ -144,7 +144,7 @@ public function handle(AppError $error) * Maps error code to a string. * * @param integer $code - * @return string + * @return mixed */ public function mapErrors($code) { diff --git a/scripts/Phalcon/Initializable.php b/scripts/Phalcon/Initializable.php index 77aac552c..1a8a64fca 100644 --- a/scripts/Phalcon/Initializable.php +++ b/scripts/Phalcon/Initializable.php @@ -689,7 +689,7 @@ function () { /** @noinspection PhpIncludeInspection */ $menu = new SidebarMenu(include $menuItems); - $menu->setDI($this); + $menu->setDI($this->di); return $menu; } diff --git a/scripts/Phalcon/Migrations.php b/scripts/Phalcon/Migrations.php index 061b44439..3065acd1c 100644 --- a/scripts/Phalcon/Migrations.php +++ b/scripts/Phalcon/Migrations.php @@ -535,7 +535,7 @@ public static function addCurrentVersion($options, $version, $startTime = null) $connection->insert(self::MIGRATION_LOG_TABLE, [$version, $startTime, $endTime], ['version', 'start_time', 'end_time']); } else { $currentVersions = self::getCompletedVersions($options); - $currentVersions[(string)$version] = 1; + $currentVersions[$version] = 1; $currentVersions = array_keys($currentVersions); sort($currentVersions); file_put_contents(self::$_storage, implode("\n", $currentVersions)); @@ -558,7 +558,7 @@ public static function removeCurrentVersion($options, $version) $connection->execute('DELETE FROM '. self::MIGRATION_LOG_TABLE .' WHERE version=\'' . $version . '\''); } else { $currentVersions = self::getCompletedVersions($options); - unset($currentVersions[(string)$version]); + unset($currentVersions[$version]); $currentVersions = array_keys($currentVersions); sort($currentVersions); file_put_contents(self::$_storage, implode("\n", $currentVersions)); diff --git a/scripts/Phalcon/Mvc/Model/Migration.php b/scripts/Phalcon/Mvc/Model/Migration.php index 751068868..2c8f90dd1 100644 --- a/scripts/Phalcon/Mvc/Model/Migration.php +++ b/scripts/Phalcon/Mvc/Model/Migration.php @@ -45,6 +45,11 @@ * * Migrations of DML y DDL over databases * @method afterCreateTable() + * @method morph() + * @method up() + * @method afterUp() + * @method down() + * @method afterDown() * * @package Phalcon\Mvc\Model */ @@ -148,7 +153,7 @@ public static function setup($database, $verbose = false) /** * Set the skip auto increment value * - * @param string $skip + * @param bool $skip */ public static function setSkipAutoIncrement($skip) { @@ -300,7 +305,7 @@ public static function generate(ItemInterface $version, $table, $exportData = nu $fieldDefinition[] = "'autoIncrement' => true"; } - if (self::$_databaseConfig->adapter == 'Postgresql' && + if (self::$_databaseConfig->path('adapter') == 'Postgresql' && in_array($field->getType(), [Column::TYPE_BOOLEAN, Column::TYPE_INTEGER, Column::TYPE_BIGINTEGER]) ) { // nothing diff --git a/scripts/Phalcon/Version/IncrementalItem.php b/scripts/Phalcon/Version/IncrementalItem.php index 07eb45233..0e8a57c2f 100644 --- a/scripts/Phalcon/Version/IncrementalItem.php +++ b/scripts/Phalcon/Version/IncrementalItem.php @@ -39,7 +39,7 @@ class IncrementalItem implements ItemInterface private $_version; /** - * @var int|string + * @var int | string */ private $_versionStamp = 0; @@ -113,7 +113,7 @@ public static function sortDesc($versions) /** * @param $versions ItemInterface[] * - * @return ItemInterface + * @return null | IncrementalItem */ public static function maximum($versions) { @@ -169,7 +169,7 @@ public static function between($initialVersion, $finalVersion, $versions) } /** - * @return int|string + * @return int | string */ public function getStamp() { @@ -177,9 +177,9 @@ public function getStamp() } /** - * @param $number + * @param int $number * - * @return string + * @return IncrementalItem */ public function addMinor($number) { diff --git a/scripts/Phalcon/Version/ItemCollection.php b/scripts/Phalcon/Version/ItemCollection.php index 2c44eab85..b25824958 100644 --- a/scripts/Phalcon/Version/ItemCollection.php +++ b/scripts/Phalcon/Version/ItemCollection.php @@ -141,7 +141,7 @@ public static function sortDesc(array $versions) * * @param array $versions * - * @return null|ItemInterface + * @return null | ItemInterface | IncrementalItem */ public static function maximum(array $versions) { @@ -160,23 +160,12 @@ public static function maximum(array $versions) * @param ItemInterface $finalVersion * @param ItemInterface[] $versions * - * @return ItemInterface[]|array + * @return ItemInterface[] | array */ - public static function between( - ItemInterface $initialVersion, - ItemInterface $finalVersion, - array $versions - ) { + public static function between(ItemInterface $initialVersion, ItemInterface $finalVersion, array $versions) + { $versions = self::sortAsc($versions); - if (!is_object($initialVersion)) { - $initialVersion = self::createItem($initialVersion); - } - - if (!is_object($finalVersion)) { - $finalVersion = self::createItem($finalVersion); - } - $betweenVersions = array(); if ($initialVersion->getStamp() == $finalVersion->getStamp()) { return $betweenVersions; // nothing to do