Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Snippet / AggregateSnippet.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Snippet;
12
13 use Behat\Behat\Context\Snippet\ContextSnippet;
14 use Behat\Gherkin\Node\StepNode;
15
16 /**
17  * Aggregates multiple similar snippets with different targets and steps.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 final class AggregateSnippet
22 {
23     /**
24      * @var Snippet[]
25      */
26     private $snippets;
27
28     /**
29      * Initializes snippet.
30      *
31      * @param Snippet[] $snippets
32      */
33     public function __construct(array $snippets)
34     {
35         $this->snippets = $snippets;
36     }
37
38     /**
39      * Returns snippet type.
40      *
41      * @return string
42      */
43     public function getType()
44     {
45         return current($this->snippets)->getType();
46     }
47
48     /**
49      * Returns snippet unique ID (step type independent).
50      *
51      * @return string
52      */
53     public function getHash()
54     {
55         return current($this->snippets)->getHash();
56     }
57
58     /**
59      * Returns definition snippet text.
60      *
61      * @return string
62      */
63     public function getSnippet()
64     {
65         return current($this->snippets)->getSnippet();
66     }
67
68     /**
69      * Returns all steps interested in this snippet.
70      *
71      * @return StepNode[]
72      */
73     public function getSteps()
74     {
75         return array_unique(
76             array_map(
77                 function (Snippet $snippet) {
78                     return $snippet->getStep();
79                 },
80                 $this->snippets
81             ),
82             SORT_REGULAR
83         );
84     }
85
86     /**
87      * Returns all snippet targets.
88      *
89      * @return string[]
90      */
91     public function getTargets()
92     {
93         return array_unique(
94             array_map(
95                 function (Snippet $snippet) {
96                     return $snippet->getTarget();
97                 },
98                 $this->snippets
99             )
100         );
101     }
102
103     /**
104      * Returns the classes used in the snippet which should be imported.
105      *
106      * @return string[]
107      */
108     public function getUsedClasses()
109     {
110         if (empty($this->snippets)) {
111             return array();
112         }
113
114         return array_unique(
115             call_user_func_array(
116                 'array_merge',
117                 array_map(
118                     function (Snippet $snippet) {
119                         if (!$snippet instanceof ContextSnippet) {
120                             return array();
121                         }
122
123                         return $snippet->getUsedClasses();
124                     },
125                     $this->snippets
126                 )
127             )
128         );
129     }
130 }