Skip to content

Commit

Permalink
#1324 - Fix models generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 13, 2019
1 parent 2c7973b commit e2e79ed
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 70 deletions.
12 changes: 4 additions & 8 deletions scripts/Phalcon/Builder/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

namespace Phalcon\Builder;

use Phalcon\Db\Adapter\Pdo\AbstractPdo;
use Phalcon\Text;
use Phalcon\Utils;
use ReflectionClass;
use Phalcon\Db\Column;
use Phalcon\Validation;
use Phalcon\Db\Adapter\Pdo;
use Phalcon\Generator\Snippet;
use Phalcon\Db\ReferenceInterface;
use Phalcon\Exception\RuntimeException;
Expand Down Expand Up @@ -148,7 +148,7 @@ public function build()

$adapterName = 'Phalcon\Db\Adapter\Pdo\\' . $adapter;
unset($configArray['adapter']);
/** @var Pdo $db */
/** @var AbstractPdo $db */
$db = new $adapterName($configArray);

$initialize = [];
Expand Down Expand Up @@ -500,10 +500,6 @@ public function build()
$license = trim(file_get_contents('license.txt')) . PHP_EOL . PHP_EOL;
}

if (false == $alreadyGetSourced) {
$methodRawCode[] = $snippet->getModelSource($this->modelOptions->getOption('name'));
}

if (false == $alreadyFind) {
$methodRawCode[] = $snippet->getModelFind($this->modelOptions->getOption('className'));
}
Expand Down Expand Up @@ -624,10 +620,10 @@ protected function getEntityClassName(ReferenceInterface $reference, $namespace)
* Get reference list from option
*
* @param string $schema
* @param Pdo $db
* @param AbstractPdo $db
* @return array
*/
protected function getReferenceList($schema, Pdo $db)
protected function getReferenceList($schema, AbstractPdo $db)
{
if ($this->modelOptions->hasOption('referenceList')) {
return $this->modelOptions->getOption('referenceList');
Expand Down
19 changes: 1 addition & 18 deletions scripts/Phalcon/Generator/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@
*/
class Snippet
{
public function getModelSource($source)
{
$getSource = <<<EOD
/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return '%s';
}
EOD;

return PHP_EOL.sprintf($getSource, $source).PHP_EOL;
}

public function getSetter($originalFieldName, $fieldName, $type, $setterName)
{
$templateSetter = <<<EOD
Expand Down Expand Up @@ -267,7 +250,7 @@ public function getModelFind($className)
* @param mixed \$parameters
* @return %s[]|%s|\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 Down
12 changes: 1 addition & 11 deletions tests/_data/console/app/models/files/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,13 @@ public function initialize()
$this->setSource("testModel");
}

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

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel[]|TestModel|\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 Down
12 changes: 1 addition & 11 deletions tests/_data/console/app/models/files/TestModel2.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ public function initialize()
$this->setSource("test-model2");
}

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

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel2[]|TestModel2|\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 Down
12 changes: 1 addition & 11 deletions tests/_data/console/app/models/files/TestModel3.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ public function initialize()
$this->setSource("test_model3");
}

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

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel3[]|TestModel3|\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 Down
12 changes: 1 addition & 11 deletions tests/_data/console/app/models/files/Testmodel4.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ public function initialize()
$this->setSource("Testmodel4");
}

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

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return Testmodel4[]|Testmodel4|\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 Down

0 comments on commit e2e79ed

Please sign in to comment.