Skip to content

Commit 7547c31

Browse files
committed
Using typehints everywhere, where possible.
Removed redundant PHPDoc typehints
1 parent 9919fbd commit 7547c31

File tree

15 files changed

+83
-138
lines changed

15 files changed

+83
-138
lines changed

lib/ContextStackTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ trait ContextStackTrait {
9191
* namespaceMap. After you're done, you can restore the old data again
9292
* with popContext.
9393
*
94-
* @return null
94+
* @return void
9595
*/
9696
function pushContext() {
9797

@@ -107,7 +107,7 @@ function pushContext() {
107107
/**
108108
* Restore the previous "context".
109109
*
110-
* @return null
110+
* @return void
111111
*/
112112
function popContext() {
113113

lib/Deserializer/functions.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@
5252
*
5353
* Attributes will be removed from the top-level elements. If elements with
5454
* the same name appear twice in the list, only the last one will be kept.
55-
*
56-
*
57-
* @param Reader $reader
58-
* @param string $namespace
59-
* @return array
6055
*/
61-
function keyValue(Reader $reader, $namespace = null) {
56+
function keyValue(Reader $reader, string $namespace = null) : array {
6257

6358
// If there's no children, we don't do anything.
6459
if ($reader->isEmptyElement) {
@@ -133,11 +128,9 @@ function keyValue(Reader $reader, $namespace = null) {
133128
* "elem5",
134129
* ];
135130
*
136-
* @param Reader $reader
137-
* @param string $namespace
138131
* @return string[]
139132
*/
140-
function enum(Reader $reader, $namespace = null) {
133+
function enum(Reader $reader, string $namespace = null) : array {
141134

142135
// If there's no children, we don't do anything.
143136
if ($reader->isEmptyElement) {
@@ -173,12 +166,9 @@ function enum(Reader $reader, $namespace = null) {
173166
* This is primarily used by the mapValueObject function from the Service
174167
* class, but it can also easily be used for more specific situations.
175168
*
176-
* @param Reader $reader
177-
* @param string $className
178-
* @param string $namespace
179169
* @return object
180170
*/
181-
function valueObject(Reader $reader, $className, $namespace) {
171+
function valueObject(Reader $reader, string $className, string $namespace) {
182172

183173
$valueObject = new $className();
184174
if ($reader->isEmptyElement) {
@@ -234,11 +224,10 @@ function valueObject(Reader $reader, $className, $namespace) {
234224
*
235225
* The repeatingElements deserializer simply returns everything as an array.
236226
*
237-
* @param Reader $reader
238-
* @param string $childElementName Element name in clark-notation
239-
* @return array
227+
* $childElementName must either be a a clark-notation element name, or if no
228+
* namespace is used, the bare element name.
240229
*/
241-
function repeatingElements(Reader $reader, $childElementName) {
230+
function repeatingElements(Reader $reader, string $childElementName) : array {
242231

243232
if ($childElementName[0] !== '{') {
244233
$childElementName = '{}' . $childElementName;

lib/Element/Base.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class Base implements Xml\Element {
2626

2727
/**
2828
* Constructor
29-
*
30-
* @param mixed $value
3129
*/
3230
function __construct($value = null) {
3331

@@ -51,7 +49,6 @@ function __construct($value = null) {
5149
*
5250
* If you are opening new elements, you must also close them again.
5351
*
54-
* @param Writer $writer
5552
* @return void
5653
*/
5754
function xmlSerialize(Xml\Writer $writer) {
@@ -78,7 +75,6 @@ function xmlSerialize(Xml\Writer $writer) {
7875
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
7976
* the next element.
8077
*
81-
* @param Xml\Reader $reader
8278
* @return mixed
8379
*/
8480
static function xmlDeserialize(Xml\Reader $reader) {

lib/Element/Cdata.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* @author Evert Pot (http://evertpot.com/)
1818
* @license http://sabre.io/license/ Modified BSD License
1919
*/
20-
class Cdata implements Xml\XmlSerializable
21-
{
20+
class Cdata implements Xml\XmlSerializable {
21+
2222
/**
2323
* CDATA element value.
2424
*
@@ -28,11 +28,8 @@ class Cdata implements Xml\XmlSerializable
2828

2929
/**
3030
* Constructor
31-
*
32-
* @param string $value
3331
*/
34-
function __construct($value)
35-
{
32+
function __construct(string $value) {
3633
$this->value = $value;
3734
}
3835

@@ -52,7 +49,6 @@ function __construct($value)
5249
*
5350
* If you are opening new elements, you must also close them again.
5451
*
55-
* @param Writer $writer
5652
* @return void
5753
*/
5854
function xmlSerialize(Xml\Writer $writer) {

lib/Element/Elements.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class Elements implements Xml\Element {
4444

4545
/**
4646
* Constructor
47-
*
48-
* @param array $value
4947
*/
5048
function __construct(array $value = []) {
5149

@@ -69,7 +67,6 @@ function __construct(array $value = []) {
6967
*
7068
* If you are opening new elements, you must also close them again.
7169
*
72-
* @param Writer $writer
7370
* @return void
7471
*/
7572
function xmlSerialize(Xml\Writer $writer) {
@@ -96,7 +93,6 @@ function xmlSerialize(Xml\Writer $writer) {
9693
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
9794
* the next element.
9895
*
99-
* @param Xml\Reader $reader
10096
* @return mixed
10197
*/
10298
static function xmlDeserialize(Xml\Reader $reader) {

lib/Element/KeyValue.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class KeyValue implements Xml\Element {
4444

4545
/**
4646
* Constructor
47-
*
48-
* @param array $value
4947
*/
5048
function __construct(array $value = []) {
5149

@@ -69,7 +67,6 @@ function __construct(array $value = []) {
6967
*
7068
* If you are opening new elements, you must also close them again.
7169
*
72-
* @param Writer $writer
7370
* @return void
7471
*/
7572
function xmlSerialize(Xml\Writer $writer) {
@@ -96,7 +93,6 @@ function xmlSerialize(Xml\Writer $writer) {
9693
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
9794
* the next element.
9895
*
99-
* @param Xml\Reader $reader
10096
* @return mixed
10197
*/
10298
static function xmlDeserialize(Xml\Reader $reader) {

lib/Element/Uri.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class Uri implements Xml\Element {
3434
*
3535
* @param string $value
3636
*/
37-
function __construct($value)
38-
{
37+
function __construct($value) {
3938
$this->value = $value;
4039
}
4140

@@ -55,7 +54,6 @@ function __construct($value)
5554
*
5655
* If you are opening new elements, you must also close them again.
5756
*
58-
* @param Writer $writer
5957
* @return void
6058
*/
6159
function xmlSerialize(Xml\Writer $writer) {
@@ -87,7 +85,6 @@ function xmlSerialize(Xml\Writer $writer) {
8785
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
8886
* the next element.
8987
*
90-
* @param Xml\Reader $reader
9188
* @return mixed
9289
*/
9390
static function xmlDeserialize(Xml\Reader $reader) {

lib/Element/XmlFragment.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@
2222
*/
2323
class XmlFragment implements Element {
2424

25+
/**
26+
* The inner XML value
27+
*
28+
* @var string
29+
*/
2530
protected $xml;
2631

27-
function __construct($xml) {
32+
/**
33+
* Constructor
34+
*/
35+
function __construct(string $xml) {
2836

2937
$this->xml = $xml;
3038

3139
}
3240

33-
function getXml() {
41+
/**
42+
* Returns the inner XML document.
43+
*/
44+
function getXml() : string {
3445

3546
return $this->xml;
3647

@@ -52,7 +63,6 @@ function getXml() {
5263
*
5364
* If you are opening new elements, you must also close them again.
5465
*
55-
* @param Writer $writer
5666
* @return void
5767
*/
5868
function xmlSerialize(Writer $writer) {
@@ -133,7 +143,6 @@ function xmlSerialize(Writer $writer) {
133143
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
134144
* the next element.
135145
*
136-
* @param Reader $reader
137146
* @return mixed
138147
*/
139148
static function xmlDeserialize(Reader $reader) {

lib/LibXMLException.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LibXMLException extends ParseException {
3232
* @param int $code
3333
* @param Throwable $previousException
3434
*/
35-
function __construct(array $errors, $code = 0, Throwable $previousException = null) {
35+
function __construct(array $errors, int $code = 0, Throwable $previousException = null) {
3636

3737
$this->errors = $errors;
3838
parent::__construct($errors[0]->message . ' on line ' . $errors[0]->line . ', column ' . $errors[0]->column, $code, $previousException);
@@ -41,10 +41,8 @@ function __construct(array $errors, $code = 0, Throwable $previousException = nu
4141

4242
/**
4343
* Returns the LibXML errors
44-
*
45-
* @return void
4644
*/
47-
function getErrors() {
45+
function getErrors() : array {
4846

4947
return $this->errors;
5048

lib/Reader.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ function getClark() {
5151
*
5252
* This function will also disable the standard libxml error handler (which
5353
* usually just results in PHP errors), and throw exceptions instead.
54-
*
55-
* @return array
5654
*/
57-
function parse() {
55+
function parse() : array {
5856

5957
$previousEntityState = libxml_disable_entity_loader(true);
6058
$previousSetting = libxml_use_internal_errors(true);
@@ -95,11 +93,8 @@ function parse() {
9593
*
9694
* If the $elementMap argument is specified, the existing elementMap will
9795
* be overridden while parsing the tree, and restored after this process.
98-
*
99-
* @param array $elementMap
100-
* @return array
10196
*/
102-
function parseGetElements(array $elementMap = null) {
97+
function parseGetElements(array $elementMap = null) : array {
10398

10499
$result = $this->parseInnerTree($elementMap);
105100
if (!is_array($result)) {
@@ -120,7 +115,6 @@ function parseGetElements(array $elementMap = null) {
120115
* If the $elementMap argument is specified, the existing elementMap will
121116
* be overridden while parsing the tree, and restored after this process.
122117
*
123-
* @param array $elementMap
124118
* @return array|string
125119
*/
126120
function parseInnerTree(array $elementMap = null) {
@@ -198,10 +192,8 @@ function parseInnerTree(array $elementMap = null) {
198192

199193
/**
200194
* Reads all text below the current element, and returns this as a string.
201-
*
202-
* @return string
203195
*/
204-
function readText() {
196+
function readText() : string {
205197

206198
$result = '';
207199
$previousDepth = $this->depth;
@@ -222,10 +214,8 @@ function readText() {
222214
* * name - A clark-notation XML element name.
223215
* * value - The parsed value.
224216
* * attributes - A key-value list of attributes.
225-
*
226-
* @return array
227217
*/
228-
function parseCurrentElement() {
218+
function parseCurrentElement() : array {
229219

230220
$name = $this->getClark();
231221

@@ -255,10 +245,8 @@ function parseCurrentElement() {
255245
* If the attributes are part of the same namespace, they will simply be
256246
* short keys. If they are defined on a different namespace, the attribute
257247
* name will be retured in clark-notation.
258-
*
259-
* @return array
260248
*/
261-
function parseAttributes() {
249+
function parseAttributes() : array {
262250

263251
$attributes = [];
264252

@@ -286,11 +274,8 @@ function parseAttributes() {
286274
/**
287275
* Returns the function that should be used to parse the element identified
288276
* by it's clark-notation name.
289-
*
290-
* @param string $name
291-
* @return callable
292277
*/
293-
function getDeserializerForElementName($name) {
278+
function getDeserializerForElementName(string $name) : callable {
294279

295280
if (!array_key_exists($name, $this->elementMap)) {
296281
if (substr($name, 0, 2) == '{}' && array_key_exists(substr($name, 2), $this->elementMap)) {

0 commit comments

Comments
 (0)