Completed
Push — master ( 091f5a...339d53 )
by Josh
04:50
created
src/Builder.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -18,118 +18,118 @@
 block discarded – undo
18 18
 
19 19
 class Builder
20 20
 {
21
-	/**
22
-	* @var InputInterface
23
-	*/
24
-	protected $input;
25
-
26
-	/**
27
-	* @var Runner
28
-	*/
29
-	protected $runner;
30
-
31
-	/**
32
-	* @var Serializer
33
-	*/
34
-	protected $serializer;
35
-
36
-	/**
37
-	* @param array $config
38
-	*/
39
-	public function __construct(array $config = [])
40
-	{
41
-		$config = $this->getConfig($config);
42
-
43
-		$this->input      = $config['input'];
44
-		$this->runner     = $config['runner'];
45
-		$this->serializer = new Serializer($config['output'], $config['escaper']);
46
-	}
47
-
48
-	/**
49
-	* Build and return a regular expression that matches all of the given strings
50
-	*
51
-	* @param  string[] $strings Literal strings to be matched
52
-	* @return string            Regular expression (without delimiters)
53
-	*/
54
-	public function build(array $strings)
55
-	{
56
-		$strings = array_unique($strings);
57
-		if ($strings === [''])
58
-		{
59
-			return '';
60
-		}
61
-
62
-		$strings = $this->splitStrings($strings);
63
-		usort($strings, __CLASS__ . '::compareStrings');
64
-		$strings = $this->runner->run($strings);
65
-
66
-		return $this->serializer->serializeStrings($strings);
67
-	}
68
-
69
-	/**
70
-	* Compare two split strings
71
-	*
72
-	* Will sort strings in ascending order
73
-	*
74
-	* @param  integer[] $a
75
-	* @param  integer[] $b
76
-	* @return integer
77
-	*/
78
-	protected function compareStrings(array $a, array $b)
79
-	{
80
-		$i   = -1;
81
-		$cnt = min(count($a), count($b));
82
-		while (++$i < $cnt)
83
-		{
84
-			if ($a[$i] !== $b[$i])
85
-			{
86
-				return $a[$i] - $b[$i];
87
-			}
88
-		}
89
-
90
-		return count($a) - count($b);
91
-	}
92
-
93
-	/**
94
-	* Build the full config array based on given input
95
-	*
96
-	* @param  array $config Sparse config
97
-	* @return array         Full config
98
-	*/
99
-	protected function getConfig(array $config)
100
-	{
101
-		$config += [
102
-			'delimiter' => '/',
103
-			'input'     => 'Bytes',
104
-			'output'    => 'Bytes'
105
-		];
106
-		$config['escaper'] = new Escaper($config['delimiter']);
107
-
108
-		$className = __NAMESPACE__ . '\\Input\\' . $config['input'];
109
-		$config['input'] = new $className;
110
-
111
-		$className = __NAMESPACE__ . '\\Output\\' . $config['output'];
112
-		$config['output'] = new $className;
113
-
114
-		$config['runner'] = new Runner;
115
-		$config['runner']->addPass(new MergePrefix);
116
-		$config['runner']->addPass(new GroupSingleCharacters);
117
-		$config['runner']->addPass(new Recurse($config['runner']));
118
-		$config['runner']->addPass(new PromoteSingleStrings);
119
-		$config['runner']->addPass(new MergeSuffix);
120
-		$config['runner']->addPass(new CoalesceSingleCharacterPrefix);
121
-
122
-		return $config;
123
-	}
124
-
125
-	/**
126
-	* Split all given strings by character
127
-	*
128
-	* @param  string[] $strings List of strings
129
-	* @return array[]           List of arrays
130
-	*/
131
-	protected function splitStrings(array $strings)
132
-	{
133
-		return array_map([$this->input, 'split'], $strings);
134
-	}
21
+    /**
22
+     * @var InputInterface
23
+     */
24
+    protected $input;
25
+
26
+    /**
27
+     * @var Runner
28
+     */
29
+    protected $runner;
30
+
31
+    /**
32
+     * @var Serializer
33
+     */
34
+    protected $serializer;
35
+
36
+    /**
37
+     * @param array $config
38
+     */
39
+    public function __construct(array $config = [])
40
+    {
41
+        $config = $this->getConfig($config);
42
+
43
+        $this->input      = $config['input'];
44
+        $this->runner     = $config['runner'];
45
+        $this->serializer = new Serializer($config['output'], $config['escaper']);
46
+    }
47
+
48
+    /**
49
+     * Build and return a regular expression that matches all of the given strings
50
+     *
51
+     * @param  string[] $strings Literal strings to be matched
52
+     * @return string            Regular expression (without delimiters)
53
+     */
54
+    public function build(array $strings)
55
+    {
56
+        $strings = array_unique($strings);
57
+        if ($strings === [''])
58
+        {
59
+            return '';
60
+        }
61
+
62
+        $strings = $this->splitStrings($strings);
63
+        usort($strings, __CLASS__ . '::compareStrings');
64
+        $strings = $this->runner->run($strings);
65
+
66
+        return $this->serializer->serializeStrings($strings);
67
+    }
68
+
69
+    /**
70
+     * Compare two split strings
71
+     *
72
+     * Will sort strings in ascending order
73
+     *
74
+     * @param  integer[] $a
75
+     * @param  integer[] $b
76
+     * @return integer
77
+     */
78
+    protected function compareStrings(array $a, array $b)
79
+    {
80
+        $i   = -1;
81
+        $cnt = min(count($a), count($b));
82
+        while (++$i < $cnt)
83
+        {
84
+            if ($a[$i] !== $b[$i])
85
+            {
86
+                return $a[$i] - $b[$i];
87
+            }
88
+        }
89
+
90
+        return count($a) - count($b);
91
+    }
92
+
93
+    /**
94
+     * Build the full config array based on given input
95
+     *
96
+     * @param  array $config Sparse config
97
+     * @return array         Full config
98
+     */
99
+    protected function getConfig(array $config)
100
+    {
101
+        $config += [
102
+            'delimiter' => '/',
103
+            'input'     => 'Bytes',
104
+            'output'    => 'Bytes'
105
+        ];
106
+        $config['escaper'] = new Escaper($config['delimiter']);
107
+
108
+        $className = __NAMESPACE__ . '\\Input\\' . $config['input'];
109
+        $config['input'] = new $className;
110
+
111
+        $className = __NAMESPACE__ . '\\Output\\' . $config['output'];
112
+        $config['output'] = new $className;
113
+
114
+        $config['runner'] = new Runner;
115
+        $config['runner']->addPass(new MergePrefix);
116
+        $config['runner']->addPass(new GroupSingleCharacters);
117
+        $config['runner']->addPass(new Recurse($config['runner']));
118
+        $config['runner']->addPass(new PromoteSingleStrings);
119
+        $config['runner']->addPass(new MergeSuffix);
120
+        $config['runner']->addPass(new CoalesceSingleCharacterPrefix);
121
+
122
+        return $config;
123
+    }
124
+
125
+    /**
126
+     * Split all given strings by character
127
+     *
128
+     * @param  string[] $strings List of strings
129
+     * @return array[]           List of arrays
130
+     */
131
+    protected function splitStrings(array $strings)
132
+    {
133
+        return array_map([$this->input, 'split'], $strings);
134
+    }
135 135
 }
136 136
\ No newline at end of file
Please login to merge, or discard this patch.