Skip to content

Commit

Permalink
fixes some phpcs and removes deprecated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingmedia committed Aug 30, 2016
1 parent 6f0ee46 commit fbc1343
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/Event/Event.php
Expand Up @@ -21,8 +21,8 @@
*
* @property string $name Name of the event
* @property object $subject The object this event applies to
* @property mixed $result Property used to retain the result value of the event listeners
* @property array $data Custom data for the method that receives the event
* @property mixed $result (deprecated) Property used to retain the result value of the event listeners
* @property array $data (deprecated) Custom data for the method that receives the event
*/
class Event
{
Expand Down Expand Up @@ -76,12 +76,8 @@ class Event
* @param object|null $subject the object that this event applies to (usually the object that is generating the event)
* @param array|null $data any value you wish to be transported with this event to it can be read by listeners
*/
public function __construct($name, $subject = null, $data = null)
public function __construct($name, $subject = null, array $data = null)
{
if ($data !== null && !is_array($data)) {
trigger_error('Data parameter will be changing to array hint typing', E_USER_DEPRECATED);
}

$this->_name = $name;
$this->_data = (array)$data;
$this->_subject = $subject;
Expand All @@ -99,11 +95,9 @@ public function __get($attribute)
return $this->{$attribute}();
}
if ($attribute === 'data') {
trigger_error('Public read access to data is deprecated, use data()', E_USER_DEPRECATED);
return $this->_data;
}
if ($attribute === 'result') {
trigger_error('Public read access to result is deprecated, use result()', E_USER_DEPRECATED);
return $this->_result;
}
}
Expand All @@ -112,16 +106,15 @@ public function __get($attribute)
* Provides backward compatibility for write access to data and result properties.
*
* @param string $attribute Attribute name.
* @param mixed $value
* @param mixed $value The value to set.
* @return void
*/
public function __set($attribute, $value)
{
if ($attribute === 'data') {
trigger_error('Public write access to data is deprecated, use setData()', E_USER_DEPRECATED);
$this->_data = (array)$value;
}
if ($attribute === 'result') {
trigger_error('Public write access to result is deprecated, use setResult()', E_USER_DEPRECATED);
$this->_result = $value;
}
}
Expand Down Expand Up @@ -177,19 +170,22 @@ public function result()
}

/**
* @param null $value
* Listeners can attach a result value to the event.
*
* @param mixed $value The value to set.
* @return $this
*/
public function setResult($value = null)
{
$this->_result = $value;

return $this;
}

/**
* Access the event data/payload.
*
* @param string|null $key
* @param string|null $key The data payload element to return, or null to return all data.
* @return array|null The data payload if $key is null, or the data value for the given $key. If the $key does not
* exist a null value is returned.
*/
Expand All @@ -198,12 +194,15 @@ public function data($key = null)
if ($key !== null) {
return isset($this->_data[$key]) ? $this->_data[$key] : null;
}

return (array)$this->_data;
}

/**
* @param array|string $key
* @param mixed $value
* Assigns a value to the data/payload of this event.
*
* @param array|string $key An array will replace all payload data, and a key will set just that array item.
* @param mixed $value The value to set.
* @return $this
*/
public function setData($key, $value = null)
Expand All @@ -213,6 +212,7 @@ public function setData($key, $value = null)
} else {
$this->_data[$key] = $value;
}

return $this;
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/TableTest.php
Expand Up @@ -27,8 +27,8 @@
use Cake\Event\EventManager;
use Cake\I18n\Time;
use Cake\ORM\Association\BelongsToMany;
use Cake\ORM\Association\HasMany;
use Cake\ORM\AssociationCollection;
use Cake\ORM\Association\HasMany;
use Cake\ORM\Entity;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
Expand Down

0 comments on commit fbc1343

Please sign in to comment.