TCollectionSubscription::getCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * TCollectionSubscription classes
5
 *
6
 * @author Brad Anderson <[email protected]>
7
 *
8
 * @link https://github.com/pradosoft/prado
9
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
10
 */
11
12
namespace Prado\Collections;
13
14
use ArrayAccess;
15
use WeakReference;
16
17
/**
18
 * TCollectionSubscription class.
19
 *
20
 * This class does the same thing as TArraySubscription except it does not pass
21
 * by reference.  This will work with ArrayAccess objects but will not work with
22
 * PHP arrays.
23
 *
24
 * This has the property Collection that provides Array access without passing by
25
 * reference.
26
 *
27
 * @author Brad Anderson <[email protected]>
28
 * @since 4.3.0
29
 */
30
class TCollectionSubscription extends TArraySubscription
31
{
32
	/**
33
	 * Constructor.
34
	 * @param ?ArrayAccess $collection The collection object being subscribed.
35
	 *   Default null.
36
	 * @param mixed $key The key of the subscription item.  Default null.
37
	 * @param mixed $item The item being subscribed to the collection.
38
	 *   Default null.
39
	 * @param null|float|int $priority The priority of the item. Default null.
40
	 * @param null|bool|int $isAssociative Is the collection associative.  this is
41
	 *   automatically set for TList and TMap.
42
	 * @param ?bool $autoSubscribe Default null for autoSubscribing when there is a
43
	 *   key or item.
44
	 */
45
	public function __construct(?ArrayAccess $collection = null, mixed $key = null, mixed $item = null, null|int|float $priority = null, null|bool|int $isAssociative = 1, ?bool $autoSubscribe = null)
46
	{
47
		parent::__construct($collection, $key, $item, $priority, $isAssociative, $autoSubscribe);
48
	}
49
50
	/**
51
	 * The ArrayAccess collection for getting the array without pass by reference.
52
	 * @param bool $weak Return the collection in as a WeakReference.
53
	 */
54
	public function getCollection(bool $weak = false): null|ArrayAccess|WeakReference
55
	{
56
		return $this->getArray($weak);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getArray($weak) could return the type array which is incompatible with the type-hinted return ArrayAccess|WeakReference|null. Consider adding an additional type-check to rule them out.
Loading history...
57
	}
58
59
	/**
60
	 * The ArrayAccess collection for setting the array without pass by reference.
61
	 * @param ?ArrayAccess $value
62
	 * @return static The current object.
63
	 */
64
	public function setCollection(?ArrayAccess $value): static
65
	{
66
		return $this->setArray($value);
67
	}
68
}
69