Formatting

This commit is contained in:
Greyscale 2024-04-14 18:11:25 +02:00
parent 167a482163
commit bc7fd3bf4f
34 changed files with 267 additions and 299 deletions

View file

@ -1,42 +1,2 @@
<?php <?php
$finder = PhpCsFixer\Finder::create(); return require("vendor/benzine/core/.php-cs-fixer.php");
if (!defined('__PHPCS_ROOT__')) {
define('__PHPCS_ROOT__', __DIR__);
}
$directories = [
__PHPCS_ROOT__.'/bin',
__PHPCS_ROOT__.'/src',
__PHPCS_ROOT__.'/test/src',
__PHPCS_ROOT__.'/test/tests',
];
if (isset($additionalDirectories)) {
$directories = array_merge($directories, $additionalDirectories);
}
foreach ($directories as $directory) {
if (file_exists($directory) && is_dir($directory)) {
$finder->in($directory);
}
}
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setHideProgress(false)
->setRules([
'@PSR2' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'@PhpCsFixer' => true,
'@PHP73Migration' => true,
'no_php4_constructor' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_superfluous_phpdoc_tags' => false,
'void_return' => true,
'yoda_style' => false,
])
->setFinder($finder)
;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Abstracts; namespace Benzine\ORM\Abstracts;
abstract class AbstractCollection abstract class AbstractCollection

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Abstracts; namespace Benzine\ORM\Abstracts;
use Benzine\ORM\Finder; use Benzine\ORM\Finder;
@ -26,9 +28,7 @@ abstract class AbstractModel implements ModelInterface, \Serializable
* Overrideable __setUp function that will allow you to hijack * Overrideable __setUp function that will allow you to hijack
* it and create any related objects that need to be recreated. * it and create any related objects that need to be recreated.
*/ */
public function __setUp(): void public function __setUp(): void {}
{
}
public function __wakeup(): void public function __wakeup(): void
{ {

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Abstracts; namespace Benzine\ORM\Abstracts;
use Benzine\ORM\Interfaces\CollectionsInterface; use Benzine\ORM\Interfaces\CollectionsInterface;
@ -19,15 +21,13 @@ abstract class AbstractService
/** /**
* @param null|array|\Closure[] $wheres * @param null|array|\Closure[] $wheres
* @param null|Sql\Expression|string $order * @param null|Sql\Expression|string $order
*
* @return CollectionsInterface
*/ */
public function getAll( public function getAll(
int $limit = null, ?int $limit = null,
int $offset = null, ?int $offset = null,
array $wheres = null, ?array $wheres = null,
$order = null, $order = null,
string $orderDirection = null ?string $orderDirection = null
): CollectionsInterface { ): CollectionsInterface {
/** @var AbstractTableGateway $tableGateway */ /** @var AbstractTableGateway $tableGateway */
$tableGateway = $this->getNewTableGatewayInstance(); $tableGateway = $this->getNewTableGatewayInstance();
@ -36,7 +36,7 @@ abstract class AbstractService
$offset, $offset,
$wheres, $wheres,
$order, $order,
null !== $orderDirection ? $orderDirection : Sql\Select::ORDER_ASCENDING null !== $orderDirection ? $orderDirection : Select::ORDER_ASCENDING
); );
$collection = $this->getNewCollectionInstance(); $collection = $this->getNewCollectionInstance();
@ -51,12 +51,10 @@ abstract class AbstractService
/** /**
* @param null|string $distinctColumn * @param null|string $distinctColumn
* @param null|array|\Closure[] $wheres * @param null|array|\Closure[] $wheres
*
* @return AbstractCollection
*/ */
public function getDistinct( public function getDistinct(
string $distinctColumn, string $distinctColumn,
array $wheres = null ?array $wheres = null
): AbstractCollection { ): AbstractCollection {
/** @var AbstractTableGateway $tableGateway */ /** @var AbstractTableGateway $tableGateway */
$tableGateway = $this->getNewTableGatewayInstance(); $tableGateway = $this->getNewTableGatewayInstance();
@ -76,11 +74,9 @@ abstract class AbstractService
/** /**
* @param null|array|\Closure[] $wheres * @param null|array|\Closure[] $wheres
*
* @return int
*/ */
public function countAll( public function countAll(
array $wheres = null ?array $wheres = null
): int { ): int {
/** @var AbstractTableGateway $tableGateway */ /** @var AbstractTableGateway $tableGateway */
$tableGateway = $this->getNewTableGatewayInstance(); $tableGateway = $this->getNewTableGatewayInstance();
@ -91,7 +87,7 @@ abstract class AbstractService
/** /**
* @return Benzine\ORM\Abstracts\Model[] * @return Benzine\ORM\Abstracts\Model[]
*/ */
public function search(Sql\Where $where, int $limit = null, int $offset = null): \Generator public function search(Sql\Where $where, ?int $limit = null, ?int $offset = null): \Generator
{ {
$tableGateway = $this->getNewTableGatewayInstance(); $tableGateway = $this->getNewTableGatewayInstance();
@ -118,7 +114,7 @@ abstract class AbstractService
abstract public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?AbstractModel; abstract public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?AbstractModel;
abstract public function getManyByField(string $field, $value, int $limit = null, int $offset = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): AbstractCollection; abstract public function getManyByField(string $field, $value, ?int $limit = null, ?int $offset = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): AbstractCollection;
abstract public function countByField(string $field, $value): int; abstract public function countByField(string $field, $value): int;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Abstracts; namespace Benzine\ORM\Abstracts;
use Benzine\Controllers\Filters\FilterCondition; use Benzine\Controllers\Filters\FilterCondition;
@ -17,6 +19,7 @@ use Laminas\Db\Sql\Predicate\PredicateInterface;
use Laminas\Db\Sql\Select; use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Where; use Laminas\Db\Sql\Where;
use Laminas\Db\TableGateway\TableGateway; use Laminas\Db\TableGateway\TableGateway;
use Laminas\Db\ResultSet\ResultSetInterface;
abstract class AbstractTableGateway extends TableGateway abstract class AbstractTableGateway extends TableGateway
{ {
@ -188,6 +191,7 @@ abstract class AbstractTableGateway extends TableGateway
public function update($data, $where = null, $oldData = []) public function update($data, $where = null, $oldData = [])
{ {
$data = array_filter($data); $data = array_filter($data);
// !\Kint::dump($data, $oldData, $where);exit; // !\Kint::dump($data, $oldData, $where);exit;
return parent::update($data, $where); return parent::update($data, $where);
} }
@ -204,9 +208,9 @@ abstract class AbstractTableGateway extends TableGateway
* @return array [ResultSet,int] Returns an array of resultSet,total_found_rows * @return array [ResultSet,int] Returns an array of resultSet,total_found_rows
*/ */
public function fetchAll( public function fetchAll(
int $limit = null, ?int $limit = null,
int $offset = null, ?int $offset = null,
array $wheres = null, ?array $wheres = null,
$order = null, $order = null,
string $direction = Select::ORDER_ASCENDING string $direction = Select::ORDER_ASCENDING
) { ) {
@ -326,7 +330,7 @@ abstract class AbstractTableGateway extends TableGateway
*/ */
public function fetchDistinct( public function fetchDistinct(
string $distinctColumn, string $distinctColumn,
array $wheres = null ?array $wheres = null
) { ) {
/** @var Select $select */ /** @var Select $select */
$select = $this->getSql()->select(); $select = $this->getSql()->select();
@ -403,9 +407,9 @@ abstract class AbstractTableGateway extends TableGateway
} }
/** /**
* @throws BenzineException
*
* @return null|ModelInterface * @return null|ModelInterface
*
* @throws BenzineException
*/ */
public function fetchRandom() public function fetchRandom()
{ {
@ -566,8 +570,6 @@ abstract class AbstractTableGateway extends TableGateway
} }
/** /**
* @param $id
*
* @return null|AbstractModel * @return null|AbstractModel
*/ */
public function getById($id) public function getById($id)
@ -576,8 +578,6 @@ abstract class AbstractTableGateway extends TableGateway
} }
/** /**
* @param $field
* @param $value
* @param $orderBy string Field to sort by * @param $orderBy string Field to sort by
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING) * @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
* *
@ -633,15 +633,11 @@ abstract class AbstractTableGateway extends TableGateway
} }
/** /**
* @param Where $where
* @param null|int $limit
* @param null|int $offset
* @param null|Expression|string $orderBy * @param null|Expression|string $orderBy
* @param string $orderDirection
* *
* @return \Laminas\Db\ResultSet\ResultSetInterface * @return ResultSetInterface
*/ */
public function getManyByWhere(Where $where, int $limit = null, int $offset = null, $orderBy = null, string $orderDirection = Select::ORDER_ASCENDING) public function getManyByWhere(Where $where, ?int $limit = null, ?int $offset = null, $orderBy = null, string $orderDirection = Select::ORDER_ASCENDING)
{ {
$select = $this->sql->select(); $select = $this->sql->select();
@ -671,11 +667,10 @@ abstract class AbstractTableGateway extends TableGateway
* @param null|int $offset int * @param null|int $offset int
* @param null|string $orderBy string Field to sort by * @param null|string $orderBy string Field to sort by
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING) * @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
* @param mixed $value
* *
* @return AbstractCollection * @return AbstractCollection
*/ */
public function getManyByField(string $field, $value, int $limit = null, int $offset = null, string $orderBy = null, string $orderDirection = Select::ORDER_ASCENDING) public function getManyByField(string $field, $value, ?int $limit = null, ?int $offset = null, ?string $orderBy = null, string $orderDirection = Select::ORDER_ASCENDING)
{ {
if ($value instanceof \DateTime) { if ($value instanceof \DateTime) {
$value = $value->format('Y-m-d H:i:s'); $value = $value->format('Y-m-d H:i:s');

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM; namespace Benzine\ORM;
use Benzine\ORM\Profiler\Profiler as BenzineProfiler; use Benzine\ORM\Profiler\Profiler as BenzineProfiler;
@ -10,7 +12,7 @@ use Laminas\Db\ResultSet;
class Adapter extends LaminasAdapter class Adapter extends LaminasAdapter
{ {
public function __construct($driver, Platform\PlatformInterface $platform = null, ResultSet\ResultSetInterface $queryResultPrototype = null, Profiler\ProfilerInterface $profiler = null) public function __construct($driver, ?Platform\PlatformInterface $platform = null, ?ResultSet\ResultSetInterface $queryResultPrototype = null, ?Profiler\ProfilerInterface $profiler = null)
{ {
parent::__construct($driver, $platform, $queryResultPrototype, $profiler); parent::__construct($driver, $platform, $queryResultPrototype, $profiler);
// if (!defined('ZEND_PROFILER_DISABLE') || ZEND_PROFILER_DISABLE == false) { // if (!defined('ZEND_PROFILER_DISABLE') || ZEND_PROFILER_DISABLE == false) {

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Components; namespace Benzine\ORM\Components;
use Benzine\ORM\Exception\DBTypeNotTranslatedException; use Benzine\ORM\Exception\DBTypeNotTranslatedException;
@ -97,8 +99,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $phpType
*
* @return Column * @return Column
*/ */
public function setPhpType($phpType) public function setPhpType($phpType)
@ -124,8 +124,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $field
*
* @return Column * @return Column
*/ */
public function setField($field) public function setField($field)
@ -154,8 +152,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $dbField
*
* @return Column * @return Column
*/ */
public function setDbField($dbField) public function setDbField($dbField)
@ -176,8 +172,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $maxDecimalPlaces
*
* @return Column * @return Column
*/ */
public function setMaxDecimalPlaces($maxDecimalPlaces) public function setMaxDecimalPlaces($maxDecimalPlaces)
@ -193,8 +187,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $defaultValue
*
* @return Column * @return Column
*/ */
public function setDefaultValue($defaultValue) public function setDefaultValue($defaultValue)
@ -233,8 +225,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $maxLength
*
* @return Column * @return Column
*/ */
public function setMaxLength($maxLength) public function setMaxLength($maxLength)
@ -250,8 +240,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $maxFieldLength
*
* @return Column * @return Column
*/ */
public function setMaxFieldLength($maxFieldLength) public function setMaxFieldLength($maxFieldLength)
@ -267,11 +255,9 @@ class Column extends Entity
} }
/** /**
* @param mixed $dbType * @return Column
* *
* @throws DBTypeNotTranslatedException * @throws DBTypeNotTranslatedException
*
* @return Column
*/ */
public function setDbType($dbType) public function setDbType($dbType)
{ {
@ -342,8 +328,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $permittedValues
*
* @return Column * @return Column
*/ */
public function setPermittedValues($permittedValues) public function setPermittedValues($permittedValues)

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Components; namespace Benzine\ORM\Components;
use Benzine\ORM\Laminator; use Benzine\ORM\Laminator;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Components; namespace Benzine\ORM\Components;
use Benzine\Exceptions\BenzineException; use Benzine\Exceptions\BenzineException;
@ -407,6 +409,7 @@ class Model extends Entity
foreach ($this->getRelatedObjects() as $relatedObject) { foreach ($this->getRelatedObjects() as $relatedObject) {
$sharedAssets[$relatedObject->getRemoteClass()] = $relatedObject; $sharedAssets[$relatedObject->getRemoteClass()] = $relatedObject;
} }
// if(count($this->getRelatedObjects())) { // if(count($this->getRelatedObjects())) {
// \Kint::dump($this->getRelatedObjects(), $sharedAssets); // \Kint::dump($this->getRelatedObjects(), $sharedAssets);
// exit; // exit;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Components; namespace Benzine\ORM\Components;
use Benzine\ORM\Connection\Database; use Benzine\ORM\Connection\Database;
@ -179,8 +181,7 @@ class RelatedModel extends Entity
return return
self::singulariseCamelCaseSentence($this->getLocalClass()) . self::singulariseCamelCaseSentence($this->getLocalClass()) .
'By' . 'By' .
$this->transCamel2Studly->transform($this->getLocalBoundColumn()) $this->transCamel2Studly->transform($this->getLocalBoundColumn());
;
} }
return $this->transCamel2Studly->transform( return $this->transCamel2Studly->transform(

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Connection; namespace Benzine\ORM\Connection;
use Benzine\ORM\Tests\App; use Benzine\ORM\Tests\App;
@ -26,8 +28,8 @@ class Database
public function __construct( public function __construct(
private Logger $logger, private Logger $logger,
string $name = null, ?string $name = null,
array $config = null ?array $config = null
) { ) {
if ($name) { if ($name) {
$this->setName($name); $this->setName($name);
@ -163,19 +165,11 @@ class Database
return new Metadata($this->getAdapter()); return new Metadata($this->getAdapter());
} }
/**
* @return array
*/
public function getIgnoredTables(): array public function getIgnoredTables(): array
{ {
return $this->ignoredTables; return $this->ignoredTables;
} }
/**
* @param array $ignoredTables
*
* @return Database
*/
public function setIgnoredTables(array $ignoredTables): Database public function setIgnoredTables(array $ignoredTables): Database
{ {
$this->ignoredTables = $ignoredTables; $this->ignoredTables = $ignoredTables;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Connection; namespace Benzine\ORM\Connection;
use Benzine\Exceptions\BenzineException; use Benzine\Exceptions\BenzineException;

View file

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Entities; namespace Benzine\ORM\Entities;
abstract class AbstractEntity abstract class AbstractEntity {}
{
}

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Entities; namespace Benzine\ORM\Entities;
class Column extends AbstractEntity class Column extends AbstractEntity

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Entities; namespace Benzine\ORM\Entities;
class Table extends AbstractEntity class Table extends AbstractEntity
@ -13,8 +15,6 @@ class Table extends AbstractEntity
} }
/** /**
* @param mixed $tableName
*
* @return Table * @return Table
*/ */
public function setTableName($tableName) public function setTableName($tableName)

View file

@ -1,9 +1,9 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Exception; namespace Benzine\ORM\Exception;
use Benzine\Exceptions\BenzineException; use Benzine\Exceptions\BenzineException;
class BenzineOrmException extends BenzineException class BenzineOrmException extends BenzineException {}
{
}

View file

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Exception; namespace Benzine\ORM\Exception;
class CollectionException extends BenzineOrmException class CollectionException extends BenzineOrmException {}
{
}

View file

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Exception; namespace Benzine\ORM\Exception;
class DBTypeNotTranslatedException extends BenzineOrmException class DBTypeNotTranslatedException extends BenzineOrmException {}
{
}

View file

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Exception; namespace Benzine\ORM\Exception;
class SchemaToAdaptorException extends BenzineOrmException class SchemaToAdaptorException extends BenzineOrmException {}
{
}

View file

@ -1,10 +1,13 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM; namespace Benzine\ORM;
use Benzine\ORM\Exception\BenzineOrmException; use Benzine\ORM\Exception\BenzineOrmException;
use Laminas\Db\Sql\Where;
class Finder extends \Laminas\Db\Sql\Where class Finder extends Where
{ {
public function __construct( public function __construct(
?array $predicates = null, ?array $predicates = null,
@ -65,11 +68,6 @@ class Finder extends \Laminas\Db\Sql\Where
return $this; return $this;
} }
/**
* @param string $orderDirection
*
* @return Finder
*/
public function orderDirection(string $orderDirection): Finder public function orderDirection(string $orderDirection): Finder
{ {
if (!in_array($orderDirection, ['desc', 'asc'], true)) { if (!in_array($orderDirection, ['desc', 'asc'], true)) {

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Interfaces; namespace Benzine\ORM\Interfaces;
use Laminas\Db\ResultSet\ResultSet; use Laminas\Db\ResultSet\ResultSet;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Interfaces; namespace Benzine\ORM\Interfaces;
interface ModelInterface interface ModelInterface

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Interfaces; namespace Benzine\ORM\Interfaces;
interface QueryStatisticInterface interface QueryStatisticInterface

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Interfaces; namespace Benzine\ORM\Interfaces;
use Laminas\Db\Sql\Expression; use Laminas\Db\Sql\Expression;
@ -12,11 +14,11 @@ interface ServiceInterface
* @return ModelInterface[] * @return ModelInterface[]
*/ */
public function getAll( public function getAll(
int $limit = null, ?int $limit = null,
int $offset = null, ?int $offset = null,
array $wheres = null, ?array $wheres = null,
$order = null, $order = null,
string $orderDirection = null ?string $orderDirection = null
); );
public function getByField(string $field, $value); public function getByField(string $field, $value);

View file

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Interfaces; namespace Benzine\ORM\Interfaces;
interface TableGatewayInterface extends \Laminas\Db\TableGateway\TableGatewayInterface interface TableGatewayInterface extends \Laminas\Db\TableGateway\TableGatewayInterface {}
{
}

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM; namespace Benzine\ORM;
use Benzine\App; use Benzine\App;
@ -23,6 +25,10 @@ use Twig\Error\LoaderError;
use Twig\Error\RuntimeError; use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError; use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader as TwigFileSystemLoader; use Twig\Loader\FilesystemLoader as TwigFileSystemLoader;
use Twig\Environment;
use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFunction;
class Laminator class Laminator
{ {
@ -70,7 +76,7 @@ class Laminator
$this->defaultEnvironment = [ $this->defaultEnvironment = [
'SCRIPT_NAME' => '/index.php', 'SCRIPT_NAME' => '/index.php',
'RAND' => rand(0, 100000000), 'RAND' => random_int(0, 100000000),
]; ];
$this->defaultHeaders = []; $this->defaultHeaders = [];
} }
@ -88,9 +94,9 @@ class Laminator
$this->setWorkPath(self::$benzineConfig->get(ConfigurationService::KEY_APP_ROOT)); $this->setWorkPath(self::$benzineConfig->get(ConfigurationService::KEY_APP_ROOT));
} }
$this->loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Generator/Templates'); $this->loader = new FilesystemLoader(__DIR__ . '/Generator/Templates');
$this->twig = new \Twig\Environment($this->loader, ['debug' => true]); $this->twig = new Environment($this->loader, ['debug' => true]);
$this->twig->addExtension(new \Twig\Extension\DebugExtension()); $this->twig->addExtension(new DebugExtension());
$this->twig->addExtension(new TransformExtension()); $this->twig->addExtension(new TransformExtension());
$this->twig->addExtension(new InflectionExtension()); $this->twig->addExtension(new InflectionExtension());
@ -98,7 +104,7 @@ class Laminator
new ArrayUniqueTwigExtension() new ArrayUniqueTwigExtension()
); );
$fct = new \Twig\TwigFunction('var_export', 'var_export'); $fct = new TwigFunction('var_export', 'var_export');
$this->twig->addFunction($fct); $this->twig->addFunction($fct);
$this->transSnake2Studly = new CaseTransformer(new Format\SnakeCase(), new Format\StudlyCaps()); $this->transSnake2Studly = new CaseTransformer(new Format\SnakeCase(), new Format\StudlyCaps());
@ -171,11 +177,9 @@ class Laminator
} }
/** /**
* @param $schemaName * @return int|string
* *
* @throws SchemaToAdaptorException * @throws SchemaToAdaptorException
*
* @return int|string
*/ */
public function schemaName2databaseName($schemaName) public function schemaName2databaseName($schemaName)
{ {
@ -255,11 +259,11 @@ class Laminator
} }
/** /**
* @return $this
*
* @throws LoaderError * @throws LoaderError
* @throws RuntimeError * @throws RuntimeError
* @throws SyntaxError * @throws SyntaxError
*
* @return $this
*/ */
public function makeLaminator() public function makeLaminator()
{ {
@ -294,7 +298,7 @@ class Laminator
if (in_array($table->getName(), $database->getIgnoredTables(), true)) { if (in_array($table->getName(), $database->getIgnoredTables(), true)) {
continue; continue;
} }
$oModel = Components\Model::Factory($this) $oModel = Model::Factory($this)
->setClassPrefix(self::$benzineConfig->get("databases/{$dbName}/class_prefix", null)) ->setClassPrefix(self::$benzineConfig->get("databases/{$dbName}/class_prefix", null))
->setNamespace(self::$benzineConfig->getNamespace()) ->setNamespace(self::$benzineConfig->getNamespace())
->setDatabase($database) ->setDatabase($database)
@ -391,11 +395,11 @@ class Laminator
/** /**
* @param Model[] $models * @param Model[] $models
* *
* @return Laminator
*
* @throws LoaderError When the template cannot be found * @throws LoaderError When the template cannot be found
* @throws SyntaxError When an error occurred during compilation * @throws SyntaxError When an error occurred during compilation
* @throws RuntimeError When an error occurred during rendering * @throws RuntimeError When an error occurred during rendering
*
* @return Laminator
*/ */
private function makeCoreFiles(array $models) private function makeCoreFiles(array $models)
{ {
@ -450,7 +454,7 @@ class Laminator
$path = $this->getWorkPath() . '/' . $path; $path = $this->getWorkPath() . '/' . $path;
if (!(new Filesystem())->exists(dirname($path))) { if (!(new Filesystem())->exists(dirname($path))) {
(new Filesystem())->mkdir(dirname($path), 0777); (new Filesystem())->mkdir(dirname($path), 0o777);
} }
if (!(new Filesystem())->exists($path) || $overwrite) { if (!(new Filesystem())->exists($path) || $overwrite) {
// printf(" [Done]" . PHP_EOL); // printf(" [Done]" . PHP_EOL);

View file

@ -1,10 +1,13 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM; namespace Benzine\ORM;
use Laminas\Db\Adapter\AdapterInterface; use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\Sql\Sql;
class LaminatorSql extends \Laminas\Db\Sql\Sql class LaminatorSql extends Sql
{ {
public function __construct(AdapterInterface $adapter, $table = null, $sqlPlatform = null) public function __construct(AdapterInterface $adapter, $table = null, $sqlPlatform = null)
{ {

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Migrations; namespace Benzine\ORM\Migrations;
abstract class AbstractMigration extends \Phinx\Migration\AbstractMigration abstract class AbstractMigration extends \Phinx\Migration\AbstractMigration

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Migrations; namespace Benzine\ORM\Migrations;
use Benzine\ORM\Tests\App; use Benzine\ORM\Tests\App;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Profiler; namespace Benzine\ORM\Profiler;
use Benzine\ORM\Interfaces\QueryStatisticInterface; use Benzine\ORM\Interfaces\QueryStatisticInterface;
@ -15,11 +17,9 @@ class Profiler implements ProfilerInterface
private array $queries = []; private array $queries = [];
private array $queryTimes = []; private array $queryTimes = [];
public function __construct(private Logger $logger) public function __construct(private Logger $logger) {}
{
}
public function getQueryStats(QueryStatisticInterface $queryStatisticClass = null): array public function getQueryStats(?QueryStatisticInterface $queryStatisticClass = null): array
{ {
return [ return [
'TotalQueries' => count($this->queryTimes), 'TotalQueries' => count($this->queryTimes),
@ -59,13 +59,13 @@ class Profiler implements ProfilerInterface
/** /**
* @return QueryStatisticInterface[] * @return QueryStatisticInterface[]
*/ */
public function getQueries(QueryStatisticInterface $queryStatisticClass = null): array public function getQueries(?QueryStatisticInterface $queryStatisticClass = null): array
{ {
$stats = []; $stats = [];
foreach ($this->queries as $uuid => [$query, $backTrace]) { foreach ($this->queries as $uuid => [$query, $backTrace]) {
if ($queryStatisticClass) { if ($queryStatisticClass) {
if (is_object($queryStatisticClass)) { if (is_object($queryStatisticClass)) {
$queryStatisticClass = get_class($queryStatisticClass); $queryStatisticClass = $queryStatisticClass::class;
} }
$stat = new $queryStatisticClass(); $stat = new $queryStatisticClass();
} else { } else {

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\Profiler; namespace Benzine\ORM\Profiler;
use Benzine\ORM\Interfaces\QueryStatisticInterface; use Benzine\ORM\Interfaces\QueryStatisticInterface;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\TabularData; namespace Benzine\ORM\TabularData;
use Benzine\ORM\Abstracts\AbstractService; use Benzine\ORM\Abstracts\AbstractService;
@ -19,7 +21,7 @@ class Table
public function __construct(AbstractService $service) public function __construct(AbstractService $service)
{ {
$this->service = $service; $this->service = $service;
$this->setName(get_class($service)); $this->setName($service::class);
$this->reload(); $this->reload();
} }

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM\TabularData; namespace Benzine\ORM\TabularData;
use Benzine\ORM\Abstracts\AbstractModel; use Benzine\ORM\Abstracts\AbstractModel;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Benzine\ORM; namespace Benzine\ORM;
use Benzine\App; use Benzine\App;