Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbaggett committed Apr 14, 2024
1 parent 167a482 commit bc7fd3b
Show file tree
Hide file tree
Showing 34 changed files with 267 additions and 299 deletions.
42 changes: 1 addition & 41 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,2 @@
<?php
$finder = PhpCsFixer\Finder::create();

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)
;
return require("vendor/benzine/core/.php-cs-fixer.php");
2 changes: 2 additions & 0 deletions src/Abstracts/AbstractCollection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Benzine\ORM\Abstracts;

abstract class AbstractCollection
Expand Down
24 changes: 12 additions & 12 deletions src/Abstracts/AbstractModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Benzine\ORM\Abstracts;

use Benzine\ORM\Finder;
Expand All @@ -9,7 +11,7 @@

abstract class AbstractModel implements ModelInterface, \Serializable
{
protected array $_primary_keys = [];
protected array $_primary_keys = [];
protected array $_autoincrement_keys = [];

protected array $_original;
Expand All @@ -26,9 +28,7 @@ public function __construct(array $data = [])
* Overrideable __setUp function that will allow you to hijack
* it and create any related objects that need to be recreated.
*/
public function __setUp(): void
{
}
public function __setUp(): void {}

public function __wakeup(): void
{
Expand All @@ -45,8 +45,8 @@ public function __toArray()
$transformer = new CaseTransformer(new Format\StudlyCaps(), new Format\StudlyCaps());

foreach ($this->getListOfProperties() as $property) {
$getFunction = "get{$property}";
$currentValue = $this->{$getFunction}();
$getFunction = "get{$property}";
$currentValue = $this->{$getFunction}();
$array[$transformer->transform($property)] = $currentValue;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public function getPrimaryKeys(): array
{
$primaryKeyValues = [];
foreach ($this->_primary_keys as $internalName => $dbName) {
$getFunction = "get{$internalName}";
$getFunction = "get{$internalName}";
$primaryKeyValues[$internalName] = $this->{$getFunction}();
}

Expand All @@ -157,7 +157,7 @@ public function getPrimaryKeys_dbColumns(): array
{
$primaryKeyValues = [];
foreach ($this->_primary_keys as $internalName => $dbName) {
$getFunction = "get{$internalName}";
$getFunction = "get{$internalName}";
$primaryKeyValues[$dbName] = $this->{$getFunction}();
}

Expand All @@ -173,7 +173,7 @@ public function getAutoIncrementKeys()
{
$autoIncrementKeyValues = [];
foreach ($this->_autoincrement_keys as $autoincrement_key => $autoincrement_db_column) {
$getFunction = "get{$autoincrement_key}";
$getFunction = "get{$autoincrement_key}";
$autoIncrementKeyValues[$autoincrement_key] = $this->{$getFunction}();
}

Expand Down Expand Up @@ -209,15 +209,15 @@ public function hasDirtyProperties(): bool
*/
public function getListOfDirtyProperties(): array
{
$transformer = new CaseTransformer(new Format\CamelCase(), new Format\StudlyCaps());
$transformer = new CaseTransformer(new Format\CamelCase(), new Format\StudlyCaps());
$dirtyProperties = [];
foreach ($this->getListOfProperties() as $property) {
$originalProperty = $transformer->transform($property);
// echo "Writing into \$this->{$originalProperty}: getListOfDirtyProperties\n";
if (!isset($this->_original[$originalProperty]) || $this->{$property} != $this->_original[$originalProperty]) {
$dirtyProperties[$property] = [
'before' => $this->_original[$originalProperty] ?? null,
'after' => $this->{$property},
'after' => $this->{$property},
];
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public function label(): string
if (method_exists($this, 'getName')) {
return $this->getName();
}
$labelParts = [];
$labelParts = [];
$primaryKeyFields = array_keys($this->getPrimaryKeys());
foreach ($primaryKeyFields as $primaryKeyField) {
$labelParts[] = $this->__get($primaryKeyField);
Expand Down
30 changes: 13 additions & 17 deletions src/Abstracts/AbstractService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Benzine\ORM\Abstracts;

use Benzine\ORM\Interfaces\CollectionsInterface;
Expand All @@ -19,24 +21,22 @@ abstract public function getTermSingular(): string;
/**
* @param null|array|\Closure[] $wheres
* @param null|Sql\Expression|string $order
*
* @return CollectionsInterface
*/
public function getAll(
int $limit = null,
int $offset = null,
array $wheres = null,
?int $limit = null,
?int $offset = null,
?array $wheres = null,
$order = null,
string $orderDirection = null
?string $orderDirection = null
): CollectionsInterface {
/** @var AbstractTableGateway $tableGateway */
$tableGateway = $this->getNewTableGatewayInstance();
$tableGateway = $this->getNewTableGatewayInstance();
[$matches, $count] = $tableGateway->fetchAll(
$limit,
$offset,
$wheres,
$order,
null !== $orderDirection ? $orderDirection : Sql\Select::ORDER_ASCENDING
null !== $orderDirection ? $orderDirection : Select::ORDER_ASCENDING
);

$collection = $this->getNewCollectionInstance();
Expand All @@ -51,15 +51,13 @@ public function getAll(
/**
* @param null|string $distinctColumn
* @param null|array|\Closure[] $wheres
*
* @return AbstractCollection
*/
public function getDistinct(
string $distinctColumn,
array $wheres = null
?array $wheres = null
): AbstractCollection {
/** @var AbstractTableGateway $tableGateway */
$tableGateway = $this->getNewTableGatewayInstance();
$tableGateway = $this->getNewTableGatewayInstance();
[$matches, $count] = $tableGateway->fetchDistinct(
$distinctColumn,
$wheres
Expand All @@ -76,11 +74,9 @@ public function getDistinct(

/**
* @param null|array|\Closure[] $wheres
*
* @return int
*/
public function countAll(
array $wheres = null
?array $wheres = null
): int {
/** @var AbstractTableGateway $tableGateway */
$tableGateway = $this->getNewTableGatewayInstance();
Expand All @@ -91,7 +87,7 @@ public function countAll(
/**
* @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();

Expand All @@ -118,7 +114,7 @@ public function getTabularData(): TabularData\Table

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;

Expand Down
Loading

0 comments on commit bc7fd3b

Please sign in to comment.