Skip to content

Commit

Permalink
fixed input type of findBy hints
Browse files Browse the repository at this point in the history
  • Loading branch information
mringler committed Nov 14, 2022
1 parent f9b9e12 commit 5e40c21
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 145 deletions.
177 changes: 42 additions & 135 deletions src/Propel/Generator/Builder/Om/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Propel\Generator\Builder\Om;

use Propel\Generator\Builder\Util\PropelTemplate;
use Propel\Generator\Model\Column;
use Propel\Generator\Model\CrossForeignKeys;
use Propel\Generator\Model\ForeignKey;
Expand Down Expand Up @@ -89,151 +90,57 @@ public function getParentClass(): string
protected function addClassOpen(string &$script): void
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$queryClass = $this->getQueryClassName();
$modelClass = $this->getObjectClassName();
$parentClass = $this->getParentClass();
$script .= "
/**
* Base class that represents a query for the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('generator.objectModel.addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('general.version') . " on:
*
* $now
*";
}

// magic orderBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
* @method $queryClass orderBy" . $column->getPhpName() . '($order = Criteria::ASC) Order by the ' . $column->getName() . ' column';
}
$script .= "
*";

// magic groupBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
* @method $queryClass groupBy" . $column->getPhpName() . '() Group by the ' . $column->getName() . ' column';
}

// override the signature of ModelCriteria::left-, right- and innerJoin to specify the class of the returned object, for IDE completion
$script .= "
*
* @method $queryClass leftJoin(\$relation) Adds a LEFT JOIN clause to the query
* @method $queryClass rightJoin(\$relation) Adds a RIGHT JOIN clause to the query
* @method $queryClass innerJoin(\$relation) Adds a INNER JOIN clause to the query
*";

$script .= "
* @method $queryClass leftJoinWith(\$relation) Adds a LEFT JOIN clause and with to the query
* @method $queryClass rightJoinWith(\$relation) Adds a RIGHT JOIN clause and with to the query
* @method $queryClass innerJoinWith(\$relation) Adds a INNER JOIN clause and with to the query
*";

$relationQueryClasses = [];

// magic XXXjoinYYY() methods, for IDE completion
foreach ($this->getTable()->getForeignKeys() as $fk) {
$relationName = $this->getFKPhpNameAffix($fk);

$script .= "
* @method $queryClass leftJoin" . $relationName . '($relationAlias = null) Adds a LEFT JOIN clause to the query using the ' . $relationName . " relation
* @method $queryClass rightJoin" . $relationName . '($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ' . $relationName . " relation
* @method $queryClass innerJoin" . $relationName . '($relationAlias = null) Adds a INNER JOIN clause to the query using the ' . $relationName . " relation
*";

$script .= "
* @method $queryClass joinWith" . $relationName . '($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the ' . $relationName . " relation
*";

$script .= "
* @method $queryClass leftJoinWith" . $relationName . '() Adds a LEFT JOIN clause and with to the query using the ' . $relationName . " relation
* @method $queryClass rightJoinWith" . $relationName . '() Adds a RIGHT JOIN clause and with to the query using the ' . $relationName . " relation
* @method $queryClass innerJoinWith" . $relationName . '() Adds a INNER JOIN clause and with to the query using the ' . $relationName . " relation
*";

$relationQueryClasses[$this->getNewStubQueryBuilder($fk->getForeignTable())->getQueryClassName(true)] = true;
}
foreach ($this->getTable()->getReferrers() as $refFK) {
$relationName = $this->getRefFKPhpNameAffix($refFK);

$script .= "
* @method $queryClass leftJoin" . $relationName . '($relationAlias = null) Adds a LEFT JOIN clause to the query using the ' . $relationName . " relation
* @method $queryClass rightJoin" . $relationName . '($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ' . $relationName . " relation
* @method $queryClass innerJoin" . $relationName . '($relationAlias = null) Adds a INNER JOIN clause to the query using the ' . $relationName . " relation
*";

$script .= "
* @method $queryClass joinWith" . $relationName . '($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the ' . $relationName . " relation
*";
$vars = [
'tableName' => $table->getName(),
'tableDesc' => $table->getDescription(),
'queryClass' => $this->getQueryClassName(),
'modelClass' => $this->getObjectClassName(),
'parentClass' => $this->getParentClass(),
'entityNotFoundExceptionClass' => $this->getEntityNotFoundExceptionClass(),
'unqualifiedClassName' => $this->getUnqualifiedClassName(),

$script .= "
* @method $queryClass leftJoinWith" . $relationName . '() Adds a LEFT JOIN clause and with to the query using the ' . $relationName . " relation
* @method $queryClass rightJoinWith" . $relationName . '() Adds a RIGHT JOIN clause and with to the query using the ' . $relationName . " relation
* @method $queryClass innerJoinWith" . $relationName . '() Adds a INNER JOIN clause and with to the query using the ' . $relationName . " relation
*";
'addTimestamp' => $this->getBuildProperty('generator.objectModel.addTimeStamp'),
'propelVersion' => $this->getBuildProperty('general.version'),

$relationQueryClasses[$this->getNewStubQueryBuilder($refFK->getTable())->getQueryClassName(true)] = true;
}
'columns' => $table->getColumns(),

if ($relationQueryClasses) {
$relationQueryClasses = implode('|', array_keys($relationQueryClasses));
$script .= "
* @method $relationQueryClasses endUse() Finalizes a secondary criteria and merges it with its primary Criteria
*";
}
'relationNames' => $this->getRelationNames(),
'relatedTableQueryClassNames' => $this->getRelatedTableQueryClassNames(),
];

// override the signature of ModelCriteria::findOne() to specify the class of the returned object, for IDE completion
$script .= "
* @method $modelClass|null findOne(?ConnectionInterface \$con = null) Return the first $modelClass matching the query
* @method $modelClass findOneOrCreate(?ConnectionInterface \$con = null) Return the first $modelClass matching the query, or a new $modelClass object populated from the query conditions when no match is found
*";
$templatePath = $this->getTemplatePath(__DIR__);

// magic findBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
* @method $modelClass|null findOneBy" . $column->getPhpName() . '(' . $column->getPhpType() . ' $' . $column->getName() . ") Return the first $modelClass filtered by the " . $column->getName() . ' column';
}
$template = new PropelTemplate();
$filePath = $templatePath . 'baseQueryClassHeader.php';
$template->setTemplateFile($filePath);

$script .= " * \n";
$script .= $template->render($vars);
}

// override the signature of ModelCriteria::require*() to specify the class of the returned object, for IDE completion
$script .= "
* @method $modelClass requirePk(\$key, ?ConnectionInterface \$con = null) Return the $modelClass by primary key and throws {$this->getEntityNotFoundExceptionClass()} when not found
* @method $modelClass requireOne(?ConnectionInterface \$con = null) Return the first $modelClass matching the query and throws {$this->getEntityNotFoundExceptionClass()} when not found
*";
/**
* Get names of all foreign key relations to and from this table.
*/
protected function getRelationNames(): array
{
$table = $this->getTable();
$fkRelationNames = array_map([$this, 'getFKPhpNameAffix'], $table->getForeignKeys());
$refFkRelationNames = array_map([$this, 'getRefFKPhpNameAffix'], $table->getReferrers());

// magic requireOneBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
* @method $modelClass requireOneBy" . $column->getPhpName() . '(' . $column->getPhpType() . ' $' . $column->getName() . ") Return the first $modelClass filtered by the " . $column->getName() . " column and throws {$this->getEntityNotFoundExceptionClass()} when not found";
}
return array_merge($fkRelationNames, $refFkRelationNames);
}

$script .= "
*
* @method {$modelClass}[]|Collection find(?ConnectionInterface \$con = null) Return $modelClass objects based on current ModelCriteria
* @psalm-method Collection&\Traversable<{$modelClass}> find(?ConnectionInterface \$con = null) Return $modelClass objects based on current ModelCriteria";
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
* @method {$modelClass}[]|Collection findBy" . $column->getPhpName() . '(' . $column->getPhpType() . ' $' . $column->getName() . ") Return $modelClass objects filtered by the " . $column->getName() . ' column' . "
* @psalm-method Collection&\Traversable<{$modelClass}> findBy" . $column->getPhpName() . '(' . $column->getPhpType() . ' $' . $column->getName() . ") Return $modelClass objects filtered by the " . $column->getName() . ' column';
}
/**
* Get query class names of all tables connected to this table with a foreign key relation.
*/
protected function getRelatedTableQueryClassNames(): array
{
$table = $this->getTable();
$fkTables = array_map(fn ($fk) => $fk->getForeignTable(), $table->getForeignKeys());
$refFkTables = array_map(fn ($fk) => $fk->getTable(), $table->getReferrers());
$relationTables = array_merge($fkTables, $refFkTables);

$script .= "
* @method {$modelClass}[]|\\Propel\\Runtime\\Util\\PropelModelPager paginate(\$page = 1, \$maxPerPage = 10, ?ConnectionInterface \$con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
* @psalm-method \\Propel\\Runtime\\Util\\PropelModelPager&\Traversable<{$modelClass}> paginate(\$page = 1, \$maxPerPage = 10, ?ConnectionInterface \$con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
*
*/
abstract class " . $this->getUnqualifiedClassName() . ' extends ' . $parentClass . "
{
";
return array_map(fn ($table) => $this->getNewStubQueryBuilder($table)->getQueryClassName(true), $relationTables);
}

/**
Expand Down Expand Up @@ -327,7 +234,7 @@ protected function addClassBody(string &$script): void
*/
protected function addEntityNotFoundExceptionClass(string &$script): void
{
$script .= "protected \$entityNotFoundExceptionClass = '" . addslashes($this->getEntityNotFoundExceptionClass()) . "';\n";
$script .= " protected \$entityNotFoundExceptionClass = '" . addslashes($this->getEntityNotFoundExceptionClass()) . "';\n";
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Manager/AbstractManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Propel\Generator\Exception\EngineException;
use Propel\Generator\Model\Database;
use Propel\Generator\Model\Schema;
use XsltProcessor;
use XSLTProcessor;

/**
* An abstract base Propel manager to perform work related to the XML schema
Expand Down Expand Up @@ -323,7 +323,7 @@ protected function loadDataModels(): void
// normalize the document using normalizer stylesheet
$xslDom = new DOMDocument('1.0', 'UTF-8');
$xslDom->load($this->xsl->getAbsolutePath());
$xsl = new XsltProcessor();
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($xslDom);
$dom = $xsl->transformToDoc($dom);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Model/Table.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

declare(strict_types=1);

/**
* MIT License. This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Propel\Generator\Model;

use Propel\Generator\Config\GeneratorConfigInterface;
Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Generator/Reverse/SqliteSchemaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ protected function addColumns(Table $table): void

if (preg_match('/^([^\(]+)\(\s*(\d+)\s*,\s*(\d+)\s*\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
$scale = $matches[3];
$size = (int)$matches[2];
$scale = (int)$matches[3];
} elseif (preg_match('/^([^\(]+)\(\s*(\d+)\s*\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
$size = (int)$matches[2];
} else {
$type = $fulltype;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Propel/Generator/Util/QuickBuilder.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php declare(strict_types = 1);
<?php

/**
* MIT License. This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Propel\Generator\Util;

use Exception;
Expand Down
4 changes: 3 additions & 1 deletion src/Propel/Generator/Util/VfsTrait.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php declare(strict_types = 1);
<?php

/**
* MIT License. This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Propel\Generator\Util;

use org\bovigo\vfs\vfsStream;
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Runtime/Connection/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function create(
): ConnectionInterface {
if (static::$useProfilerConnection) {
$connectionClass = ProfilerConnectionWrapper::class;
} else if (isset($configuration['classname'])) {
} elseif (isset($configuration['classname'])) {
$connectionClass = $configuration['classname'];
} else {
$connectionClass = $defaultConnectionClass;
Expand Down
Loading

0 comments on commit 5e40c21

Please sign in to comment.