Test Setup Failed
Push — master ( 1ad5e1...90657a )
by Php Easy Api
09:49
created
src/resta/Router/RouteMatching.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      * @param ApplicationContracts $app
19 19
      * @param null|object $route
20 20
      */
21
-    public function __construct(ApplicationContracts $app, $route=null)
21
+    public function __construct(ApplicationContracts $app, $route = null)
22 22
     {
23 23
         parent::__construct($app);
24 24
 
@@ -34,53 +34,53 @@  discard block
 block discarded – undo
34 34
     {
35 35
         $routes = $this->route->getRoutes();
36 36
 
37
-        if(!isset($routes['pattern'])){
37
+        if (!isset($routes['pattern'])) {
38 38
             return [];
39 39
         }
40 40
 
41 41
         $patterns = $routes['pattern'];
42
-        $urlRoute = array_filter(route(),'strlen');
42
+        $urlRoute = array_filter(route(), 'strlen');
43 43
 
44 44
         $patternList = [];
45 45
 
46
-        foreach($routes['data'] as $patternKey=>$routeData){
47
-            if($routeData['http']==httpMethod()){
48
-                $patternList[$patternKey]=$patterns[$patternKey];
46
+        foreach ($routes['data'] as $patternKey=>$routeData) {
47
+            if ($routeData['http']==httpMethod()) {
48
+                $patternList[$patternKey] = $patterns[$patternKey];
49 49
             }
50 50
         }
51 51
 
52 52
         $scoredList = [];
53 53
 
54
-        foreach ($patternList as $key=>$pattern){
54
+        foreach ($patternList as $key=>$pattern) {
55 55
 
56 56
             $patternCount = $this->getPatternRealCount($pattern);
57 57
 
58
-            if(count($urlRoute)==0 && count($urlRoute)==0) return array_key_first($patternList);
58
+            if (count($urlRoute)==0 && count($urlRoute)==0) return array_key_first($patternList);
59 59
 
60
-            if(isset($patternCount['optional'])){
61
-                $optionalCount = count($patternCount['default']) + count($patternCount['optional']);
60
+            if (isset($patternCount['optional'])) {
61
+                $optionalCount = count($patternCount['default'])+count($patternCount['optional']);
62 62
             }
63 63
 
64
-            if(count($urlRoute) == count($patternCount['default']) ||
64
+            if (count($urlRoute)==count($patternCount['default']) ||
65 65
                 (isset($optionalCount) && count($urlRoute)>count($patternCount['default']) && $optionalCount>=count($urlRoute))
66
-            ){
66
+            ) {
67 67
 
68
-                foreach ($pattern as $pkey=>$item){
68
+                foreach ($pattern as $pkey=>$item) {
69 69
 
70
-                    if($this->route->isMatchVaribleRegexPattern($item)===false){
71
-                        if(isset($urlRoute[$pkey]) && $urlRoute[$pkey]==$item){
70
+                    if ($this->route->isMatchVaribleRegexPattern($item)===false) {
71
+                        if (isset($urlRoute[$pkey]) && $urlRoute[$pkey]==$item) {
72 72
                             $scoredList[$key][] = 3;
73 73
                         }
74 74
                     }
75 75
 
76
-                    if($this->route->isMatchVaribleRegexPattern($item) && !$this->route->isOptionalVaribleRegexPattern($item)){
77
-                        if(isset($urlRoute[$pkey])){
76
+                    if ($this->route->isMatchVaribleRegexPattern($item) && !$this->route->isOptionalVaribleRegexPattern($item)) {
77
+                        if (isset($urlRoute[$pkey])) {
78 78
                             $scoredList[$key][] = 2;
79 79
                         }
80 80
                     }
81 81
 
82
-                    if($this->route->isMatchVaribleRegexPattern($item) && $this->route->isOptionalVaribleRegexPattern($item)){
83
-                        if(isset($urlRoute[$pkey])){
82
+                    if ($this->route->isMatchVaribleRegexPattern($item) && $this->route->isOptionalVaribleRegexPattern($item)) {
83
+                        if (isset($urlRoute[$pkey])) {
84 84
                             $scoredList[$key][] = 1;
85 85
                         }
86 86
                     }
@@ -104,14 +104,14 @@  discard block
 block discarded – undo
104 104
         $list = [];
105 105
         $list['default'] = [];
106 106
 
107
-        foreach ($pattern as $key=>$value){
108
-            if(($this->route->isMatchVaribleRegexPattern($value)===false) || ($this->route->isMatchVaribleRegexPattern($value)
109
-                    && !$this->route->isOptionalVaribleRegexPattern($value))){
107
+        foreach ($pattern as $key=>$value) {
108
+            if (($this->route->isMatchVaribleRegexPattern($value)===false) || ($this->route->isMatchVaribleRegexPattern($value)
109
+                    && !$this->route->isOptionalVaribleRegexPattern($value))) {
110 110
                 $list['default'][$key] = $value;
111 111
             }
112 112
 
113
-            if(($this->route->isMatchVaribleRegexPattern($value)
114
-                && $this->route->isOptionalVaribleRegexPattern($value))){
113
+            if (($this->route->isMatchVaribleRegexPattern($value)
114
+                && $this->route->isOptionalVaribleRegexPattern($value))) {
115 115
                 $list['optional'][] = true;
116 116
             }
117 117
         }
@@ -125,19 +125,19 @@  discard block
 block discarded – undo
125 125
      * @param array $scoredList
126 126
      * @return false|int|string
127 127
      */
128
-    private function showKeyAccordingToScoredList($scoredList=array())
128
+    private function showKeyAccordingToScoredList($scoredList = array())
129 129
     {
130 130
         $scored = [];
131 131
 
132
-        foreach($scoredList as $key=>$item){
132
+        foreach ($scoredList as $key=>$item) {
133 133
             $scored[$key] = array_sum($item);
134 134
         }
135 135
 
136
-        if(count($scored)){
136
+        if (count($scored)) {
137 137
             $arrayCountValues = array_count_values($scored);
138 138
 
139
-            if(count($scored)!==$arrayCountValues[max($scored)]){
140
-                return array_search(max($scored),$scored);
139
+            if (count($scored)!==$arrayCountValues[max($scored)]) {
140
+                return array_search(max($scored), $scored);
141 141
             }
142 142
 
143 143
         }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
         $route = route();
158 158
 
159 159
         foreach ($pattern as $key=>$item) {
160
-            if($this->route->isMatchVaribleRegexPattern($item)===false){
161
-                if(isset($route[$key]) && $item!==$route[$key]){
160
+            if ($this->route->isMatchVaribleRegexPattern($item)===false) {
161
+                if (isset($route[$key]) && $item!==$route[$key]) {
162 162
                     return false;
163 163
                 }
164 164
             }
Please login to merge, or discard this patch.