Completed
Push — master ( d1c60d...2373c3 )
by Josh
03:29
created

AbstractPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 60
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 1
A afterRun() 0 9 3
A beforeRun() 0 10 3
processStrings() 0 1 ?
1
<?php
2
3
/**
4
* @package   s9e\RegexpBuilder
5
* @copyright Copyright (c) 2016 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\RegexpBuilder\Passes;
9
10
abstract class AbstractPass implements PassInterface
11
{
12
	/**
13
	* @var bool Whether the current set of strings is optional
14
	*/
15
	protected $isOptional;
16
17
	/**
18
	* {@inheritdoc}
19
	*/
20 27
	public function run(array $strings)
21
	{
22 27
		$strings = $this->beforeRun($strings);
23 27
		$strings = $this->processStrings($strings);
24 27
		$strings = $this->afterRun($strings);
25
26 27
		return $strings;
27
	}
28
29
	/**
30
	* Process the list of strings after the pass is run
31
	*
32
	* @param  array[] $strings
33
	* @return array[]
34
	*/
35 27
	protected function afterRun(array $strings)
36
	{
37 27
		if ($this->isOptional && $strings[0] !== [])
38
		{
39 2
			array_unshift($strings, []);
40
		}
41
42 27
		return $strings;
43
	}
44
45
	/**
46
	* Prepare the list of strings before the pass is run
47
	*
48
	* @param  array[] $strings
49
	* @return array[]
50
	*/
51 27
	protected function beforeRun(array $strings)
52
	{
53 27
		$this->isOptional = (isset($strings[0]) && $strings[0] === []);
54 27
		if ($this->isOptional)
55
		{
56 2
			array_shift($strings);
57
		}
58
59 27
		return $strings;
60
	}
61
62
	/**
63
	* Process a given list of strings
64
	*
65
	* @param  array[] $strings
66
	* @return array[]
67
	*/
68
	abstract protected function processStrings(array $strings);
69
}