Skip to content

Commit

Permalink
Merge pull request #212 from dereuromark/phpstan
Browse files Browse the repository at this point in the history
Remove deprecations.
  • Loading branch information
dereuromark committed Oct 28, 2018
2 parents 04c861d + 9d1a719 commit 45805fe
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 162 deletions.
7 changes: 3 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
backupStaticAttributes="false"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php">
bootstrap="tests/bootstrap.php">
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
Expand All @@ -20,9 +19,9 @@
</testsuite>
</testsuites>
<listeners>
<listener class="\Cake\TestSuite\Fixture\FixtureInjector">
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
<object class="Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
Expand Down
25 changes: 14 additions & 11 deletions src/Controller/Component/CommonComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function startup(Event $event) {
if ($this->Controller->request->getQuery() && !Configure::read('DataPreparation.notrim')) {
$this->Controller->request->query = Utility::trimDeep($this->Controller->request->getQuery());
}
if (!empty($this->Controller->request->params['pass']) && !Configure::read('DataPreparation.notrim')) {
$this->Controller->request->params['pass'] = Utility::trimDeep($this->Controller->request->params['pass']);
if ($this->Controller->request->getParam('pass') && !Configure::read('DataPreparation.notrim')) {
$this->Controller->request->params['pass'] = Utility::trimDeep($this->Controller->request->getParam('pass'));
}
}

Expand Down Expand Up @@ -131,7 +131,8 @@ public function loadHelper($helpers = []) {
* @return mixed
*/
public function getPassedParam($var, $default = null) {
return (isset($this->Controller->request->params['pass'][$var])) ? $this->Controller->request->params['pass'][$var] : $default;
$passed = $this->Controller->request->getParam('pass');
return (isset($passed[$var])) ? $passed[$var] : $default;
}

/**
Expand All @@ -156,14 +157,16 @@ public static function defaultUrlParams() {
* @return mixed URL
*/
public function currentUrl($asString = false) {
if (isset($this->Controller->request->params['prefix']) && mb_strpos($this->Controller->request->params['action'], $this->Controller->request->params['prefix']) === 0) {
$action = mb_substr($this->Controller->request->params['action'], mb_strlen($this->Controller->request->params['prefix']) + 1);
} else {
$action = $this->Controller->request->params['action'];
}
$action = $this->Controller->request->getParam('action');

$url = array_merge($this->Controller->request->params['pass'], ['prefix' => isset($this->Controller->request->params['prefix']) ? $this->Controller->request->params['prefix'] : null,
'plugin' => $this->Controller->request->params['plugin'], 'action' => $action, 'controller' => $this->Controller->request->params['controller']]);
$passed = (array)$this->Controller->request->getParam('pass');
$url = [
'prefix' => $this->Controller->request->getParam('prefix'),
'plugin' => $this->Controller->request->getParam('plugin'),
'action' => $action,
'controller' => $this->Controller->request->getParam('controller'),
];
$url = array_merge($passed, $url);

if ($asString === true) {
return Router::url($url);
Expand Down Expand Up @@ -239,7 +242,7 @@ public function autoPostRedirect($whereTo, $conditionalAutoRedirect = true, $sta
if (!empty($controller) && $refererController !== '*' && $refererController !== $controller) {
continue;
}
if (empty($controller) && $refererController !== $this->Controller->request->params['controller']) {
if (empty($controller) && $refererController !== $this->Controller->request->getParam('controller')) {
continue;
}
if (!in_array($referer['action'], (array)$this->Controller->autoRedirectActions, true)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/BitmaskedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function encodeBitmaskConditions(Query $query) {
}
$key = $comparison->getField();

if ($key !== $mappedField && $key !== $this->_table->alias() . '.' . $mappedField) {
if ($key !== $mappedField && $key !== $this->_table->getAlias() . '.' . $mappedField) {
return $comparison;
}

Expand Down Expand Up @@ -300,7 +300,7 @@ public function encodeBitmaskData(EntityInterface $entity) {
*/
protected function _getDefault($field) {
$default = null;
$schema = $this->_table->schema()->column($field);
$schema = $this->_table->getSchema()->getColumn($field);

if ($schema && isset($schema['default'])) {
$default = $schema['default'];
Expand Down
1 change: 0 additions & 1 deletion src/Model/Behavior/ConfirmableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function build(Validator $validator, $name = 'default') {
'last' => true]
);
$validator->requirePresence($field);
//$validator->allowEmpty($field, false);
}

}
5 changes: 3 additions & 2 deletions src/Model/Behavior/JsonableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tools\Model\Behavior;

use ArrayObject;
use Cake\Collection\CollectionInterface;
use Cake\Database\Type;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
Expand Down Expand Up @@ -89,7 +90,7 @@ public function initialize(array $config = []) {
throw new RuntimeException('Fields and Map need to be of the same length if map is specified.');
}
foreach ($this->_config['fields'] as $field) {
$this->_table->schema()->columnType($field, 'array');
$this->_table->getSchema()->setColumnType($field, 'array');
}
if ($this->_config['encodeParams']['options'] === null) {
$options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_ERROR_INF_OR_NAN | JSON_PARTIAL_OUTPUT_ON_ERROR;
Expand All @@ -110,7 +111,7 @@ public function initialize(array $config = []) {
* @return void
*/
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
$query->formatResults(function ($results) {
$query->formatResults(function (CollectionInterface $results) {
return $results->map(function ($row) {
if (!$row instanceOf Entity) {
return $row;
Expand Down
10 changes: 6 additions & 4 deletions src/Model/Behavior/NeighborBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ class NeighborBehavior extends Behavior {
* @param array $options
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function neighbors($id, array $options = []) {
if (!$id) {
throw new InvalidArgumentException("The 'id' key is required for find('neighbors')");
}

$sortField = $this->_table->hasField('created') ? 'created' : $this->_table->primaryKey();
$sortField = $this->_table->hasField('created') ? 'created' : $this->_table->getPrimaryKey();
$defaults = [
'sortField' => $this->_table->alias() . '.' . $sortField,
'sortField' => $this->_table->getAlias() . '.' . $sortField,
];
$options += $defaults;

Expand All @@ -39,7 +41,7 @@ public function neighbors($id, array $options = []) {
$sortDirSymb = $normalDirection ? ['>=', '<='] : ['<=', '>='];

if (empty($options['value'])) {
$data = $this->_table->find('all', ['conditions' => [$this->_table->primaryKey() => $id]])->first();
$data = $this->_table->find('all', ['conditions' => [$this->_table->getPrimaryKey() => $id]])->first();
list($model, $sortField) = pluginSplit($options['sortField']);
$options['value'] = $data[$sortField];
}
Expand All @@ -54,7 +56,7 @@ public function neighbors($id, array $options = []) {
if (!empty($options['fields'])) {
$findOptions['fields'] = $options['fields'];
}
$findOptions['conditions'][$this->_table->alias() . '.' . $this->_table->primaryKey() . ' !='] = $id;
$findOptions['conditions'][$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() . ' !='] = $id;

$prevOptions = $findOptions;
$prevOptions['conditions'] = Hash::merge($prevOptions['conditions'], [$options['sortField'] . ' ' . $sortDirSymb[1] => $options['value']]);
Expand Down
14 changes: 7 additions & 7 deletions src/Model/Behavior/PasswordableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ public function needsPasswordRehash($hash) {
*/
public function validateCurrentPwd($pwd, $context) {
$uid = null;
if (!empty($context['data'][$this->_table->primaryKey()])) {
$uid = $context['data'][$this->_table->primaryKey()];
if (!empty($context['data'][$this->_table->getPrimaryKey()])) {
$uid = $context['data'][$this->_table->getPrimaryKey()];
} else {
trigger_error('No user id given');
return false;
Expand Down Expand Up @@ -429,14 +429,14 @@ public function validateNotSame($data, $options, $context) {
*/
public function validateNotSameHash($data, $context) {
$field = $this->_config['field'];
if (empty($context['data'][$this->_table->primaryKey()])) {
if (empty($context['data'][$this->_table->getPrimaryKey()])) {
return true;
}

$primaryKey = $context['data'][$this->_table->primaryKey()];
$primaryKey = $context['data'][$this->_table->getPrimaryKey()];
$value = $context['data'][$context['field']];

$dbValue = $this->_table->find()->where([$this->_table->alias() . '.' . $this->_table->primaryKey() => $primaryKey])->first();
$dbValue = $this->_table->find()->where([$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => $primaryKey])->first();
if (!$dbValue) {
return true;
}
Expand All @@ -457,8 +457,8 @@ public function validateNotSameHash($data, $context) {
protected function _validateSameHash($pwd, $context) {
$field = $this->_config['field'];

$primaryKey = $context['data'][$this->_table->primaryKey()];
$dbValue = $this->_table->find()->where([$this->_table->alias() . '.' . $this->_table->primaryKey() => $primaryKey])->first();
$primaryKey = $context['data'][$this->_table->getPrimaryKey()];
$dbValue = $this->_table->find()->where([$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => $primaryKey])->first();
if (!$dbValue) {
return false;
}
Expand Down
13 changes: 7 additions & 6 deletions src/Model/Behavior/ResetBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ public function __construct(Table $table, array $config = []) {
*
* @param array $params
* @return int Modified records
* @throws \RuntimeException
*/
public function resetRecords(array $params = []) {
$defaults = [
'page' => 1,
'limit' => $this->_config['limit'],
'fields' => [],
'order' => [$this->_table->alias() . '.' . $this->_table->primaryKey() => 'ASC'],
'order' => [$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => 'ASC'],
'conditions' => $this->_config['scope'],
];
if (!empty($this->_config['fields'])) {
Expand All @@ -96,11 +97,11 @@ public function resetRecords(array $params = []) {
throw new RuntimeException('Table does not have field ' . $field);
}
}
$defaults['fields'] = array_merge([$this->_table->alias() . '.' . $this->_table->primaryKey()], $this->_config['fields']);
$defaults['fields'] = array_merge([$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey()], $this->_config['fields']);
} else {
$defaults['fields'] = [$this->_table->alias() . '.' . $this->_table->primaryKey()];
if ($this->_table->displayField() !== $this->_table->primaryKey()) {
$defaults['fields'][] = $this->_table->alias() . '.' . $this->_table->displayField();
$defaults['fields'] = [$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey()];
if ($this->_table->getDisplayField() !== $this->_table->getPrimaryKey()) {
$defaults['fields'][] = $this->_table->getAlias() . '.' . $this->_table->getDisplayField();
}
}

Expand Down Expand Up @@ -151,7 +152,7 @@ public function resetRecords(array $params = []) {

$res = $this->_table->save($record, compact('validate', 'fieldList'));
if (!$res) {
throw new RuntimeException(print_r($record->errors(), true));
throw new RuntimeException(print_r($record->getErrors(), true));
}
$modified++;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Model/Behavior/SluggedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SluggedBehavior extends Behavior {
*/
public function __construct(Table $table, array $config = []) {
$this->_defaultConfig['notices'] = Configure::read('debug');
$this->_defaultConfig['label'] = $table->displayField();
$this->_defaultConfig['label'] = $table->getDisplayField();
foreach ($this->_defaultConfig['replace'] as $key => $value) {
$this->_defaultConfig['replace'][$key] = __d('tools', $value);
}
Expand All @@ -117,7 +117,7 @@ public function __construct(Table $table, array $config = []) {
*/
public function initialize(array $config) {
if ($this->_config['length'] === null) {
$length = $this->_table->schema()->column($this->_config['field'])['length'];
$length = $this->_table->getSchema()->getColumn($this->_config['field'])['length'];
$this->_config['length'] = $length ?: 0;
}

Expand All @@ -128,15 +128,15 @@ public function initialize(array $config) {
}
if ($this->_config['length']) {
foreach ($label as $field) {
$alias = $this->_table->alias();
$alias = $this->_table->getAlias();
if (strpos($field, '.')) {
list($alias, $field) = explode('.', $field);
if (!$this->_table->$alias->hasField($field)) {
throw new RuntimeException('(SluggedBehavior::setup) model ' . $this->_table->$alias->alias() . ' is missing the field ' . $field .
' (specified in the setup for model ' . $this->_table->alias() . ') ');
throw new RuntimeException('(SluggedBehavior::setup) model ' . $this->_table->$alias->getAlias() . ' is missing the field ' . $field .
' (specified in the setup for model ' . $this->_table->getAlias() . ') ');
}
} elseif (!$this->_table->hasField($field) && !method_exists($this->_table->entityClass(), '_get' . Inflector::classify($field))) {
throw new RuntimeException('(SluggedBehavior::setup) model ' . $this->_table->alias() . ' is missing the field ' . $field . ' specified in the setup.');
throw new RuntimeException('(SluggedBehavior::setup) model ' . $this->_table->getAlias() . ' is missing the field ' . $field . ' specified in the setup.');
}
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ public function slug(EntityInterface $entity, array $options = []) {
*/
public function needsSlugUpdate(EntityInterface $entity, $deep = false) {
foreach ((array)$this->_config['label'] as $label) {
if ($entity->dirty($label)) {
if ($entity->isDirty($label)) {
return true;
}
}
Expand Down Expand Up @@ -308,12 +308,12 @@ public function generateSlug($value, EntityInterface $entity = null) {
if (!$entity) {
throw new RuntimeException('Needs an Entity to work on');
}
$field = $this->_table->alias() . '.' . $this->_config['field'];
$field = $this->_table->getAlias() . '.' . $this->_config['field'];
$conditions = [$field => $slug];
$conditions = array_merge($conditions, $this->_config['scope']);
$id = $entity->get($this->_table->primaryKey());
$id = $entity->get($this->_table->getPrimaryKey());
if ($id) {
$conditions['NOT'][$this->_table->alias() . '.' . $this->_table->primaryKey()] = $id;
$conditions['NOT'][$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey()] = $id;
}
$i = 0;
$suffix = '';
Expand Down
9 changes: 6 additions & 3 deletions src/Model/Behavior/ToggleBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\ORM\Behavior;
use Symfony\Component\Console\Exception\LogicException;
use LogicException;

/**
* ToggleBehavior
Expand Down Expand Up @@ -53,7 +53,7 @@ public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $
$order = $this->getConfig('findOrder');
if ($order === null) {
$order = [];
if ($this->_table->schema()->column('modified')) {
if ($this->_table->getSchema()->getColumn('modified')) {
$order['modified'] = 'DESC';
}
}
Expand All @@ -72,6 +72,7 @@ public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $
* @param \Cake\Datasource\EntityInterface $entity
* @param \ArrayObject $options
* @return void
* @throws \LogicException
*/
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
$field = $this->getConfig('field');
Expand Down Expand Up @@ -101,13 +102,15 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o
* @param \ArrayObject $options
*
* @return void
*
* @throws \LogicException
*/
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) {
if ($this->_config['on'] !== 'afterSave') {
return;
}

if (!$entity->dirty($this->getConfig('field'))) {
if (!$entity->isDirty($this->getConfig('field'))) {
return;
}

Expand Down
Loading

0 comments on commit 45805fe

Please sign in to comment.