Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       14 / 14  | 
               | 
       100.00%  | 
       6 / 6  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| AclRole |         | 
       100.00%  | 
       14 / 14  | 
               | 
       100.00%  | 
       6 / 6  | 
       10 |         | 
       100.00%  | 
       1 / 1  | 
      
| addChild |         | 
       100.00%  | 
       6 / 6  | 
               | 
       100.00%  | 
       1 / 1  | 
       4 | |||
| hasChildren |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| getChildren |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| setParent |         | 
       100.00%  | 
       4 / 4  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| getParent |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| hasParent |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| 1 | <?php | 
| 2 | /** | 
| 3 | * Pop PHP Framework (http://www.popphp.org/) | 
| 4 | * | 
| 5 | * @link https://github.com/popphp/popphp-framework | 
| 6 | * @author Nick Sagona, III <dev@noladev.com> | 
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. | 
| 8 | * @license https://www.popphp.org/license New BSD License | 
| 9 | */ | 
| 10 | |
| 11 | /** | 
| 12 | * @namespace | 
| 13 | */ | 
| 14 | namespace Pop\Acl; | 
| 15 | |
| 16 | /** | 
| 17 | * Acl role class | 
| 18 | * | 
| 19 | * @category Pop | 
| 20 | * @package Pop\Acl | 
| 21 | * @author Nick Sagona, III <dev@noladev.com> | 
| 22 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. | 
| 23 | * @license https://www.popphp.org/license New BSD License | 
| 24 | * @version 4.1.3 | 
| 25 | */ | 
| 26 | class AclRole extends AbstractAcl | 
| 27 | { | 
| 28 | |
| 29 | /** | 
| 30 | * Role children | 
| 31 | * @var array | 
| 32 | */ | 
| 33 | protected array $children = []; | 
| 34 | |
| 35 | /** | 
| 36 | * Role parent | 
| 37 | * @var ?AclRole | 
| 38 | */ | 
| 39 | protected ?AclRole $parent = null; | 
| 40 | |
| 41 | /** | 
| 42 | * Add a child role | 
| 43 | * | 
| 44 | * @param AclRole $child | 
| 45 | * @return AclRole | 
| 46 | */ | 
| 47 | public function addChild(AclRole $child): AclRole | 
| 48 | { | 
| 49 | if ($child->getName() !== $this->getName()) { | 
| 50 | if (!in_array($child, $this->children, true)) { | 
| 51 | $this->children[] = $child; | 
| 52 | } | 
| 53 | if ($child->getParent() === null) { | 
| 54 | $child->setParent($this); | 
| 55 | } | 
| 56 | } | 
| 57 | return $this; | 
| 58 | } | 
| 59 | |
| 60 | /** | 
| 61 | * Has child roles | 
| 62 | * | 
| 63 | * @return bool | 
| 64 | */ | 
| 65 | public function hasChildren(): bool | 
| 66 | { | 
| 67 | return (count($this->children) > 0); | 
| 68 | } | 
| 69 | |
| 70 | /** | 
| 71 | * Get child roles | 
| 72 | * | 
| 73 | * @return array | 
| 74 | */ | 
| 75 | public function getChildren(): array | 
| 76 | { | 
| 77 | return $this->children; | 
| 78 | } | 
| 79 | |
| 80 | /** | 
| 81 | * Set the parent role | 
| 82 | * | 
| 83 | * @param AclRole $parent | 
| 84 | * @return AclRole | 
| 85 | */ | 
| 86 | public function setParent(AclRole $parent): AclRole | 
| 87 | { | 
| 88 | if ($parent->getName() !== $this->getName()) { | 
| 89 | $this->parent = $parent; | 
| 90 | $this->parent->addChild($this); | 
| 91 | } | 
| 92 | return $this; | 
| 93 | } | 
| 94 | |
| 95 | /** | 
| 96 | * Get the role parent | 
| 97 | * | 
| 98 | * @return AclRole|null | 
| 99 | */ | 
| 100 | public function getParent(): AclRole|null | 
| 101 | { | 
| 102 | return $this->parent; | 
| 103 | } | 
| 104 | |
| 105 | /** | 
| 106 | * See if the role has a parent | 
| 107 | * | 
| 108 | * @return bool | 
| 109 | */ | 
| 110 | public function hasParent(): bool | 
| 111 | { | 
| 112 | return ($this->parent !== null); | 
| 113 | } | 
| 114 | |
| 115 | } |