Navigation Menu

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 string $name Name of the event
* @property object $subject The object this event applies to * @property object $subject The object this event applies to
* @property mixed $result Property used to retain the result value of the event listeners * @property mixed $result (deprecated) Property used to retain the result value of the event listeners
* @property array $data Custom data for the method that receives the event * @property array $data (deprecated) Custom data for the method that receives the event
*/ */
class 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 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 * @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->_name = $name;
$this->_data = (array)$data; $this->_data = (array)$data;
$this->_subject = $subject; $this->_subject = $subject;
Expand All @@ -99,11 +95,9 @@ public function __get($attribute)
return $this->{$attribute}(); return $this->{$attribute}();
} }
if ($attribute === 'data') { if ($attribute === 'data') {
trigger_error('Public read access to data is deprecated, use data()', E_USER_DEPRECATED);
return $this->_data; return $this->_data;
} }
if ($attribute === 'result') { if ($attribute === 'result') {
trigger_error('Public read access to result is deprecated, use result()', E_USER_DEPRECATED);
return $this->_result; return $this->_result;
} }
} }
Expand All @@ -112,16 +106,15 @@ public function __get($attribute)
* Provides backward compatibility for write access to data and result properties. * Provides backward compatibility for write access to data and result properties.
* *
* @param string $attribute Attribute name. * @param string $attribute Attribute name.
* @param mixed $value * @param mixed $value The value to set.
* @return void
*/ */
public function __set($attribute, $value) public function __set($attribute, $value)
{ {
if ($attribute === 'data') { if ($attribute === 'data') {
trigger_error('Public write access to data is deprecated, use setData()', E_USER_DEPRECATED);
$this->_data = (array)$value; $this->_data = (array)$value;
} }
if ($attribute === 'result') { if ($attribute === 'result') {
trigger_error('Public write access to result is deprecated, use setResult()', E_USER_DEPRECATED);
$this->_result = $value; $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 * @return $this
*/ */
public function setResult($value = null) public function setResult($value = null)
{ {
$this->_result = $value; $this->_result = $value;

return $this; return $this;
} }


/** /**
* Access the event data/payload. * 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 * @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. * exist a null value is returned.
*/ */
Expand All @@ -198,12 +194,15 @@ public function data($key = null)
if ($key !== null) { if ($key !== null) {
return isset($this->_data[$key]) ? $this->_data[$key] : null; return isset($this->_data[$key]) ? $this->_data[$key] : null;
} }

return (array)$this->_data; return (array)$this->_data;
} }


/** /**
* @param array|string $key * Assigns a value to the data/payload of this event.
* @param mixed $value *
* @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 * @return $this
*/ */
public function setData($key, $value = null) public function setData($key, $value = null)
Expand All @@ -213,6 +212,7 @@ public function setData($key, $value = null)
} else { } else {
$this->_data[$key] = $value; $this->_data[$key] = $value;
} }

return $this; 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\Event\EventManager;
use Cake\I18n\Time; use Cake\I18n\Time;
use Cake\ORM\Association\BelongsToMany; use Cake\ORM\Association\BelongsToMany;
use Cake\ORM\Association\HasMany;
use Cake\ORM\AssociationCollection; use Cake\ORM\AssociationCollection;
use Cake\ORM\Association\HasMany;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use Cake\ORM\Query; use Cake\ORM\Query;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
Expand Down

0 comments on commit fbc1343

Please sign in to comment.