From c08a53690e4b66b2163445891aa6936897d6ac5c Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 14 Sep 2022 17:09:50 +0545 Subject: [PATCH] Move public string 'name' into Node All of Component, Parameter and Property have 'name'. Moving it into Node helps phpstan to understand that 'name' always exists. --- lib/Component.php | 11 +++-------- lib/Node.php | 9 +++++++++ lib/Parameter.php | 5 ----- lib/Property.php | 7 ------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/Component.php b/lib/Component.php index 76cfa6984..e82f6e792 100644 --- a/lib/Component.php +++ b/lib/Component.php @@ -22,17 +22,12 @@ */ class Component extends Node { - /** - * Component name. - * - * This will contain a string such as VEVENT, VTODO, VCALENDAR, VCARD. - */ - public string $name; - /** * A list of properties and/or sub-components. * - * @var array|Property> + * ToDo: maybe be more specific array|Property> + * + * @var array> */ protected array $children = []; diff --git a/lib/Node.php b/lib/Node.php index 5ecc2c00e..ac62857fb 100644 --- a/lib/Node.php +++ b/lib/Node.php @@ -54,6 +54,15 @@ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \Js */ protected ?Component $root; + /** + * Name of the item (a Component or Parameter or Property). + * + * This will contain a component name such as VEVENT, VTODO, VCALENDAR, VCARD. + * Or a parameter name (vCard 2.1 allows parameters to be encoded without a name) + * Or a property name such as DTSTART, SUMMARY, FN. + */ + public ?string $name; + /** * Serializes the node into a mimedir format. */ diff --git a/lib/Parameter.php b/lib/Parameter.php index 0082bce31..b636fa118 100644 --- a/lib/Parameter.php +++ b/lib/Parameter.php @@ -18,11 +18,6 @@ */ class Parameter extends Node { - /** - * Parameter name. - */ - public string $name; - /** * vCard 2.1 allows parameters to be encoded without a name. * diff --git a/lib/Property.php b/lib/Property.php index 305fffb72..4cd64f5ea 100644 --- a/lib/Property.php +++ b/lib/Property.php @@ -25,13 +25,6 @@ abstract class Property extends Node */ public ?Component $root; - /** - * Property name. - * - * This will contain a string such as DTSTART, SUMMARY, FN. - */ - public ?string $name; - /** * Property group. *