Passed
Push — master ( 246025...18c029 )
by Fabio
05:31
created

TCollectionSubscription   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCollection() 0 3 1
A setCollection() 0 3 1
1
<?php
2
/**
3
 * TCollectionSubscription classes
4
 *
5
 * @author Brad Anderson <[email protected]>
6
 *
7
 * @link https://github.com/pradosoft/prado
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 */
10
11
namespace Prado\Collections;
12
13
use ArrayAccess;
14
use WeakReference;
15
16
/**
17
 * TCollectionSubscription class.
18
 *
19
 * This class does the same thing as TArraySubscription except it does not pass
20
 * by reference.  This will work with ArrayAccess objects but will not work with
21
 * PHP arrays.
22
 *
23
 * This has the property Collection that provides Array access without passing by
24
 * reference.
25
 *
26
 * @author Brad Anderson <[email protected]>
27
 * @since 4.2.3
28
 */
29
class TCollectionSubscription extends TArraySubscription
30
{
31
	/**
32
	 * Constructor.
33
	 * @param ?ArrayAccess $collection The collection object being subscribed.
34
	 *   Default null.
35
	 * @param mixed $key The key of the subscription item.  Default null.
36
	 * @param mixed $item The item being subscribed to the collection.
37
	 *   Default null.
38
	 * @param null|float|int $priority The priority of the item. Default null.
39
	 * @param null|bool|int $isAssociative Is the collection associative.  this is
40
	 *   automatically set for TList and TMap.
41
	 * @param ?bool $autoSubscribe Default null for autoSubscribing when there is a
42
	 *   key or item.
43
	 */
44
	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)
45
	{
46
		parent::__construct($collection, $key, $item, $priority, $isAssociative, $autoSubscribe);
47
	}
48
49
	/**
50
	 * The ArrayAccess collection for getting the array without pass by reference.
51
	 * @param bool $weak Return the collection in as a WeakReference.
52
	 */
53
	public function getCollection(bool $weak = false): null|ArrayAccess|WeakReference
54
	{
55
		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...
56
	}
57
58
	/**
59
	 * The ArrayAccess collection for setting the array without pass by reference.
60
	 * @param ?ArrayAccess $value
61
	 * @return static The current object.
62
	 */
63
	public function setCollection(?ArrayAccess $value): static
64
	{
65
		return $this->setArray($value);
66
	}
67
}
68