Browse Source

Add native type hints for Event properties

Corey Taylor 4 years ago
parent
commit
7dfa5be8fa

+ 1 - 1
phpstan-baseline.neon

@@ -256,7 +256,7 @@ parameters:
 			path: src/Event/Event.php
 
 		-
-			message: "#^Property Cake\\\\Event\\\\Event\\<TSubject\\>\\:\\:\\$_subject \\(TSubject\\|null\\) does not accept object\\|null\\.$#"
+			message: "#^PHPDoc tag @var for property Cake\\\\Event\\\\Event\\:\\:\\$_subject with type TSubject\\|null is not subtype of native type object\\|null\\.$#"
 			count: 1
 			path: src/Event/Event.php
 

+ 1 - 1
src/Event/Decorator/AbstractDecorator.php

@@ -33,7 +33,7 @@ abstract class AbstractDecorator
      *
      * @var array
      */
-    protected $_options = [];
+    protected array $_options = [];
 
     /**
      * Constructor.

+ 5 - 5
src/Event/Event.php

@@ -30,7 +30,7 @@ class Event implements EventInterface
      *
      * @var string
      */
-    protected $_name;
+    protected string $_name;
 
     /**
      * The object this event applies to (usually the same object that generates the event)
@@ -38,14 +38,14 @@ class Event implements EventInterface
      * @var object|null
      * @psalm-var TSubject|null
      */
-    protected $_subject;
+    protected ?object $_subject = null;
 
     /**
      * Custom data for the method that receives the event
      *
      * @var array
      */
-    protected $_data;
+    protected array $_data;
 
     /**
      * Property used to retain the result value of the event listeners
@@ -54,14 +54,14 @@ class Event implements EventInterface
      *
      * @var mixed
      */
-    protected $result;
+    protected mixed $result = null;
 
     /**
      * Flags an event as stopped or not, default is false
      *
      * @var bool
      */
-    protected $_stopped = false;
+    protected bool $_stopped = false;
 
     /**
      * Constructor

+ 2 - 2
src/Event/EventDispatcherTrait.php

@@ -27,14 +27,14 @@ trait EventDispatcherTrait
      *
      * @var \Cake\Event\EventManagerInterface|null
      */
-    protected $_eventManager;
+    protected ?EventManagerInterface $_eventManager = null;
 
     /**
      * Default class name for new event objects.
      *
      * @var string
      */
-    protected $_eventClass = Event::class;
+    protected string $_eventClass = Event::class;
 
     /**
      * Returns the Cake\Event\EventManager manager instance for this object.

+ 1 - 1
src/Event/EventList.php

@@ -29,7 +29,7 @@ class EventList implements ArrayAccess, Countable
      *
      * @var array<\Cake\Event\EventInterface>
      */
-    protected $_events = [];
+    protected array $_events = [];
 
     /**
      * Empties the list of dispatched events.

+ 6 - 6
src/Event/EventManager.php

@@ -31,42 +31,42 @@ class EventManager implements EventManagerInterface
      *
      * @var int
      */
-    public static $defaultPriority = 10;
+    public static int $defaultPriority = 10;
 
     /**
      * The globally available instance, used for dispatching events attached from any scope
      *
      * @var \Cake\Event\EventManager|null
      */
-    protected static $_generalManager;
+    protected static ?EventManager $_generalManager = null;
 
     /**
      * List of listener callbacks associated to
      *
      * @var array
      */
-    protected $_listeners = [];
+    protected array $_listeners = [];
 
     /**
      * Internal flag to distinguish a common manager from the singleton
      *
      * @var bool
      */
-    protected $_isGlobal = false;
+    protected bool $_isGlobal = false;
 
     /**
      * The event list object.
      *
      * @var \Cake\Event\EventList|null
      */
-    protected $_eventList;
+    protected ?EventList $_eventList = null;
 
     /**
      * Enables automatic adding of events to the event list object if it is present.
      *
      * @var bool
      */
-    protected $_trackEvents = false;
+    protected bool $_trackEvents = false;
 
     /**
      * Returns the globally available instance of a Cake\Event\EventManager