Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-1491: Fixed optional options checks on model create #1494

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [4.0.6](https://github.com/phalcon/cphalcon/releases/tag/v4.0.6)
## Fixed
- Fixed model findFirst return type error [#1478](https://github.com/phalcon/phalcon-devtools/issues/1478)
- Added trailing semicolon to scaffolding crud views getters [#1477](https://github.com/phalcon/phalcon-devtools/issues/1477)
- Fixed optional options (namespace, abstract) checks on model create [#1491](https://github.com/phalcon/phalcon-devtools/issues/1491)

# [4.0.5](https://github.com/phalcon/cphalcon/releases/tag/v4.0.5) (2021-03-14)
## Fixed
- Fixed model creation failure in webtools due to wrong variable mutation [#1415](https://github.com/phalcon/phalcon-devtools/issues/1415)
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Component/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function build(): void
}

$entityNamespace = '';
if ($this->modelOptions->getOption('namespace')) {
if ($this->modelOptions->hasOption('namespace')) {
$entityNamespace = $this->modelOptions->getOption('namespace')."\\";
}

Expand All @@ -190,7 +190,7 @@ public function build(): void

foreach ($db->describeReferences($this->modelOptions->getOption('name'), $schema) as $reference) {
$entityNamespace = '';
if ($this->modelOptions->getOption('namespace')) {
if ($this->modelOptions->hasOption('namespace')) {
$entityNamespace = $this->modelOptions->getOption('namespace');
}

Expand Down
22 changes: 11 additions & 11 deletions src/Builder/Component/Scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,33 +309,33 @@ private function makeField(string $attribute, int $dataType, $relationField, arr
$code .= "\t\t" . '<?php echo $this->tag->select(["' . $attribute . '", $' .
$selectDefinition[$attribute]['varName'] . ', "using" => "' .
$selectDefinition[$attribute]['primaryKey'] . ',' . $selectDefinition[$attribute]['detail'] .
'", "useDummy" => true), "class" => "form-control", "id" => "' . $id . '"] ?>';
'", "useDummy" => true), "class" => "form-control", "id" => "' . $id . '"]; ?>';
} else {
switch ($dataType) {
case Column::TYPE_ENUM: // enum
$code .= "\t\t" . '<?php echo $this->tag->selectStatic(["' . $attribute .
'", [], "class" => "form-control", "id" => "' . $id . '"]) ?>';
'", [], "class" => "form-control", "id" => "' . $id . '"]); ?>';
break;
case Column::TYPE_CHAR:
$code .= "\t\t" . '<?php echo $this->tag->textField(["' . $attribute .
'", "class" => "form-control", "id" => "' . $id . '"]) ?>';
'", "class" => "form-control", "id" => "' . $id . '"]); ?>';
break;
case Column::TYPE_DECIMAL:
case Column::TYPE_INTEGER:
$code .= "\t\t" . '<?php echo $this->tag->textField(["' . $attribute .
'", "type" => "number", "class" => "form-control", "id" => "' . $id . '"]) ?>';
'", "type" => "number", "class" => "form-control", "id" => "' . $id . '"]); ?>';
break;
case Column::TYPE_DATE:
$code .= "\t\t" . '<?php echo $this->tag->textField(["' . $attribute .
'", "type" => "date", "class" => "form-control", "id" => "' . $id . '"]) ?>';
'", "type" => "date", "class" => "form-control", "id" => "' . $id . '"]); ?>';
break;
case Column::TYPE_TEXT:
$code .= "\t\t" . '<?php echo $this->tag->textArea(["' . $attribute .
'", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "' . $id . '"]) ?>';
'", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "' . $id . '"]); ?>';
break;
default:
$code .= "\t\t" . '<?php echo $this->tag->textField(["' . $attribute .
'", "size" => 30, "class" => "form-control", "id" => "' . $id . '"]) ?>';
'", "size" => 30, "class" => "form-control", "id" => "' . $id . '"]); ?>';
break;
}
}
Expand Down Expand Up @@ -565,8 +565,8 @@ private function makeLayouts()
// View model layout
$code = '';
if ($this->options->has('theme')) {
$code .= '<?php $this->tag->stylesheetLink("themes/lightness/style") ?>'.PHP_EOL;
$code .= '<?php $this->tag->stylesheetLink("themes/base") ?>'.PHP_EOL;
$code .= '<?php $this->tag->stylesheetLink("themes/lightness/style"); ?>'.PHP_EOL;
$code .= '<?php $this->tag->stylesheetLink("themes/base"); ?>'.PHP_EOL;
$code .= '<div class="ui-layout" align="center">' . PHP_EOL;
} else {
$code .= '<div class="center-block">' . PHP_EOL;
Expand Down Expand Up @@ -733,9 +733,9 @@ private function makeViewSearch(): void
} else {
$detailField = ucfirst($this->options->get('allReferences')[$fieldName]['detail']);
$rowCode .= '$' . $this->options->get('singular') . '->get' .
$this->options->get('allReferences')[$fieldName]['tableName'] . '()->get' . $detailField . '()';
$this->options->get('allReferences')[$fieldName]['tableName'] . '()->get' . $detailField . '();';
}
$rowCode .= ' ?></td>' . PHP_EOL;
$rowCode .= '; ?></td>' . PHP_EOL;
}

$idField = $this->options->get('attributes')[0];
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ public function getModelFindFirst($className)
* Allows to query the first record that match the specified conditions
*
* @param mixed \$parameters
* @return %s|\Phalcon\Mvc\Model\ResultInterface
* @return %s|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null
*/
public static function findFirst(\$parameters = null)
public static function findFirst(\$parameters = null): ?\Phalcon\Mvc\ModelInterface
{
return parent::findFirst(\$parameters);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/console/app/models/files/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInt
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel|\Phalcon\Mvc\Model\ResultInterface
* @return TestModel|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null
*/
public static function findFirst($parameters = null)
public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface
{
return parent::findFirst($parameters);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/console/app/models/files/TestModel2.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInt
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel2|\Phalcon\Mvc\Model\ResultInterface
* @return TestModel2|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null
*/
public static function findFirst($parameters = null)
public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface
{
return parent::findFirst($parameters);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/console/app/models/files/TestModel3.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInt
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel3|\Phalcon\Mvc\Model\ResultInterface
* @return TestModel3|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null
*/
public static function findFirst($parameters = null)
public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface
{
return parent::findFirst($parameters);
}
Expand Down
16 changes: 3 additions & 13 deletions tests/_data/console/app/models/files/TestModel5.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,13 @@ public function initialize()
$this->setSource("TestModel5");
}

/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'TestModel5';
}

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel5[]|TestModel5|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null)
public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInterface
{
return parent::find($parameters);
}
Expand All @@ -52,9 +42,9 @@ public static function find($parameters = null)
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel5|\Phalcon\Mvc\Model\ResultInterface
* @return TestModel5|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null
*/
public static function findFirst($parameters = null)
public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface
{
return parent::findFirst($parameters);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/console/app/models/files/Testmodel4.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInt
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return Testmodel4|\Phalcon\Mvc\Model\ResultInterface
* @return Testmodel4|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null
*/
public static function findFirst($parameters = null)
public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface
{
return parent::findFirst($parameters);
}
Expand Down