Skip to content

Commit

Permalink
refactored remaining codesniffer problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipl. jur. Sascha Müller (Sacom EDV) committed Apr 24, 2020
1 parent 209cac9 commit 2b04e9e
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 112 deletions.
2 changes: 0 additions & 2 deletions src/Event/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Cake\Event\EventListenerInterface;
use Cake\Event\EventManagerTrait;


/**
* Class EventListener
*
Expand Down Expand Up @@ -66,7 +65,6 @@ public function execute()
* Check whether or not a bake call is a certain type.
*
* @param string|array $type The type of file you want to check.
*
* @return bool Whether or not the bake template is the type you are checking.
*/
public function isType($type)
Expand Down
22 changes: 7 additions & 15 deletions src/Event/VersionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;

/**
Expand All @@ -32,8 +31,7 @@ class VersionListener extends EventListener
/**
* Called before the entity template is rendered
*
* @param Event $event An Event instance
*
* @param \Cake\Event\Event $event An Event instance
* @return void
*/
public function beforeRenderEntity(Event $event)
Expand All @@ -44,8 +42,7 @@ public function beforeRenderEntity(Event $event)
/**
* Called before the test case template is rendered
*
* @param Event $event An Event instance
*
* @param \Cake\Event\Event $event An Event instance
* @return void
*/
public function beforeRenderTestCase(Event $event)
Expand All @@ -62,8 +59,7 @@ public function beforeRenderTestCase(Event $event)
/**
* Called before the table template is rendered
*
* @param Event $event An Event instance
*
* @param \Cake\Event\Event $event An Event instance
* @return void
*/
public function beforeRenderTable(Event $event)
Expand All @@ -75,8 +71,7 @@ public function beforeRenderTable(Event $event)
/**
* Removes unnecessary associations
*
* @param Event $event An Event instance
*
* @param \Cake\Event\Event $event An Event instance
* @return void
*/
protected function fixVersionTables(Event $event)
Expand All @@ -96,9 +91,8 @@ protected function fixVersionTables(Event $event)
/**
* Attaches the behavior and modifies associations as necessary
*
* @param Event $event An Event instance
* @param \Cake\Event\Event $event An Event instance
* @param string $tableSuffix a suffix for the primary table
*
* @return bool true if modified, false otherwise
*/
protected function checkAssociation(Event $event, $tableSuffix)
Expand All @@ -125,8 +119,7 @@ protected function checkAssociation(Event $event, $tableSuffix)
/**
* Removes unnecessary belongsTo associations
*
* @param Event $event An Event instance
*
* @param \Cake\Event\Event $event An Event instance
* @return array
*/
protected function modifyBelongsTo(Event $event)
Expand All @@ -147,8 +140,7 @@ protected function modifyBelongsTo(Event $event)
/**
* Removes unnecessary rulesChecker entries
*
* @param Event $event An Event instance
*
* @param \Cake\Event\Event $event An Event instance
* @return array
*/
protected function modifyRulesChecker(Event $event)
Expand Down
3 changes: 0 additions & 3 deletions src/Model/Behavior/Version/VersionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Josegonzalez\Version\Model\Behavior\Version;

use Cake\Collection\Collection;
use Cake\ORM\TableRegistry;

/**
Expand All @@ -32,7 +31,6 @@ trait VersionTrait
*
* @param int $versionId The version number to retrieve
* @param bool $reset If true, will re-retrieve the related version collection
*
* @return \Cake\ORM\Entity|null
*/
public function version($versionId, $reset = false)
Expand All @@ -49,7 +47,6 @@ public function version($versionId, $reset = false)
* Retrieves the related versions for the current entity
*
* @param bool $reset If true, will re-retrieve the related version collection
*
* @return \Cake\Collection\CollectionInterface
*/
public function versions($reset = false)
Expand Down
41 changes: 15 additions & 26 deletions src/Model/Behavior/VersionBehavior.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types=1);

/**
* Class VersionBehavior
*
Expand All @@ -19,7 +20,6 @@
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\ORM\Behavior;
use Cake\ORM\Entity;
use Cake\ORM\Query;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
Expand All @@ -44,7 +44,6 @@
*/
class VersionBehavior extends Behavior
{

/**
* Table instance
*
Expand Down Expand Up @@ -81,7 +80,6 @@ class VersionBehavior extends Behavior
* the constructor and call parent.
*
* @param array $config The configuration settings provided to this behavior.
*
* @return void
*/
public function initialize(array $config): void
Expand All @@ -100,13 +98,12 @@ public function initialize(array $config): void
* used for fetching all versions for each record in the bound table
*
* @param string $table the table name to use for storing each field version
*
* @return void
*/
public function setupFieldAssociations($table)
{
$options = [
'table' => $table
'table' => $table,
];

foreach ($this->fields() as $field) {
Expand All @@ -121,7 +118,6 @@ public function setupFieldAssociations($table)
*
* @param string|null $field Field name for per-field association.
* @param array $options Association options.
*
* @return \Cake\ORM\Association
*/
public function versionAssociation($field = null, $options = [])
Expand All @@ -135,7 +131,7 @@ public function versionAssociation($field = null, $options = [])
'className' => $this->_config['versionTable'],
'foreignKey' => $this->_config['foreignKey'],
'strategy' => 'subquery',
'dependent' => true
'dependent' => true,
];

if ($field) {
Expand All @@ -144,14 +140,14 @@ public function versionAssociation($field = null, $options = [])
$name . '.model' => $model,
$name . '.field' => $field,
],
'propertyName' => $field . '_version'
'propertyName' => $field . '_version',
];
} else {
$options += [
'conditions' => [
$name . '.model' => $model
$name . '.model' => $model,
],
'propertyName' => '__version'
'propertyName' => '__version',
];
}

Expand All @@ -168,7 +164,6 @@ public function versionAssociation($field = null, $options = [])
* @param \Cake\Event\Event $event The beforeSave event that was fired
* @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
* @param \ArrayObject $options the options passed to the save method
*
* @return void
*/
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
Expand Down Expand Up @@ -214,9 +209,10 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o
}

$new[$field] = new $entityClass(
$data, [
$data,
[
'useSetters' => false,
'markNew' => true
'markNew' => true,
]
);
}
Expand All @@ -232,7 +228,6 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o
*
* @param \Cake\Event\Event $event The beforeSave event that was fired
* @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
*
* @return void
*/
public function afterSave(Event $event, EntityInterface $entity)
Expand All @@ -245,7 +240,6 @@ public function afterSave(Event $event, EntityInterface $entity)
* Return the last version id
*
* @param \Cake\Datasource\EntityInterface $entity Entity.
*
* @return int
*/
public function getVersionId(EntityInterface $entity)
Expand All @@ -266,7 +260,7 @@ public function getVersionId(EntityInterface $entity)
->select(['version_id'])
->where(
[
'model' => $this->_config['referenceName']
'model' => $this->_config['referenceName'],
] + $extractedKey
)
->order(['id desc'])
Expand All @@ -292,7 +286,6 @@ public function getVersionId(EntityInterface $entity)
*
* @param \Cake\ORM\Query $query The original query to modify
* @param array $options Options
*
* @return \Cake\ORM\Query
*/
public function findVersions(Query $query, array $options)
Expand Down Expand Up @@ -328,7 +321,6 @@ public function findVersions(Query $query, array $options)
* into each entity under the `_versions` key
*
* @param \Cake\Datasource\ResultSetInterface $results Results to modify.
*
* @return \Cake\Collection\CollectionInterface
*/
public function groupVersions($results)
Expand All @@ -345,12 +337,12 @@ function (EntityInterface $row) use ($property) {
foreach ($grouped->combine('field', 'content', 'version_id') as $versionId => $keys) {
$entityClass = $this->_table->getEntityClass();
$versionData = [
$versionField => $versionId
$versionField => $versionId,
];

$keys = $this->convertFieldsToType($keys, 'toPHP');

/* @var \Cake\Datasource\EntityInterface $versionRow */
/** @var \Cake\Datasource\EntityInterface $versionRow */
$versionRow = $grouped->match(['version_id' => $versionId])->first();

foreach ($this->_config['additionalVersionFields'] as $mappedField => $field) {
Expand All @@ -361,10 +353,11 @@ function (EntityInterface $row) use ($property) {
}

$version = new $entityClass(
$keys + $versionData, [
$keys + $versionData,
[
'markNew' => false,
'useSetters' => false,
'markClean' => true
'markClean' => true,
]
);
$result[$versionId] = $version;
Expand All @@ -384,7 +377,6 @@ function (EntityInterface $row) use ($property) {
* Returns the versions of a specific entity.
*
* @param \Cake\Datasource\EntityInterface $entity Entity.
*
* @return \Cake\Collection\CollectionInterface
*/
public function getVersions(EntityInterface $entity)
Expand Down Expand Up @@ -429,7 +421,6 @@ protected function fields()
* Returns an array with foreignKey value.
*
* @param \Cake\Datasource\EntityInterface $entity Entity.
*
* @return array
*/
protected function extractForeignKey($entity)
Expand All @@ -445,7 +436,6 @@ protected function extractForeignKey($entity)
* Returns default version association name.
*
* @param string $field Field name.
*
* @return string
*/
protected function associationName($field = null)
Expand Down Expand Up @@ -482,7 +472,6 @@ protected function referenceName()
*
* @param array $fields Fields to convert
* @param string $direction Direction (toPHP or toDatabase)
*
* @return array
*/
protected function convertFieldsToType(array $fields, $direction)
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/ArticlesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ArticlesFixture extends TestFixture
'body' => 'text',
'published' => ['type' => 'string', 'length' => 1, 'default' => 'N'],
'settings' => ['type' => 'json', 'null' => true],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
];

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/ArticlesTagsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ArticlesTagsFixture extends TestFixture
'tag_id' => ['type' => 'integer'],
'version_id' => ['type' => 'integer', 'null' => true],
'sort_order' => ['type' => 'integer', 'default' => 1],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']]]
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']]],
];

/**
Expand Down
Loading

0 comments on commit 2b04e9e

Please sign in to comment.