Test Failed
Push — master ( 0ddf40...2f9b76 )
by Auke
03:22
created
src/store/PSQLStore.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function cd($path)
35 35
     {
36
-        return new self( $this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path) );
36
+        return new self($this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path));
37 37
     }
38 38
 
39 39
     /**
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
      * @param string $path
43 43
      * @return mixed
44 44
      */
45
-    public function find($query, $path='')
45
+    public function find($query, $path = '')
46 46
     {
47 47
         $path = \arc\path::collapse($path, $this->path);
48 48
         $sql  = $this->queryParser->parse($query, $path);
49
-        return ($this->resultHandler)( $sql, [] );
49
+        return ($this->resultHandler)($sql, []);
50 50
     }
51 51
 
52 52
     /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @param string $path
55 55
      * @return mixed
56 56
      */
57
-    public function get($path='')
57
+    public function get($path = '')
58 58
     {
59 59
         $path   = \arc\path::collapse($path, $this->path);
60 60
         $parent = ($path=='/' ? '' : \arc\path::parent($path));
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
      * @param string $top
76 76
      * @return mixed
77 77
      */
78
-    public function parents($path='', $top='/')
78
+    public function parents($path = '', $top = '/')
79 79
     {
80
-        $path   = \arc\path::collapse($path, $this->path);
80
+        $path = \arc\path::collapse($path, $this->path);
81 81
         return ($this->resultHandler)(
82 82
             /** @lang sql */
83 83
             'lower(path)=lower(substring(:path,1,length(path))) '
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      * @param string $path
92 92
      * @return mixed
93 93
      */
94
-    public function ls($path='')
94
+    public function ls($path = '')
95 95
     {
96
-        $path   = \arc\path::collapse($path, $this->path);
96
+        $path = \arc\path::collapse($path, $this->path);
97 97
         return ($this->resultHandler)('parent=:path', [':path' => $path]);
98 98
     }
99 99
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param string $path
103 103
      * @return bool
104 104
      */
105
-    public function exists($path='')
105
+    public function exists($path = '')
106 106
     {
107 107
         $path   = \arc\path::collapse($path, $this->path);
108 108
         $query  = $this->db->prepare('select count(*) from nodes where path=:path');
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function initialize() {
118 118
         try {
119
-            if ($result=$this->exists('/')) {
119
+            if ($result = $this->exists('/')) {
120 120
                 return false;
121 121
             }
122 122
         } catch (\PDOException $e) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 SQL;
152 152
         $queries[] = "create index link_from on links(from_id);";
153 153
         $queries[] = "create index link_to on links(to_id);";
154
-        foreach ( $queries as $query ) {
154
+        foreach ($queries as $query) {
155 155
             $result = $this->db->exec($query);
156 156
             if ($result===false) {
157 157
                 $this->db->exec('rollback;');
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 
163 163
         return $this->save(\arc\prototype::create([
164 164
             'name' => 'Root'
165
-        ]),'/');
165
+        ]), '/');
166 166
     }
167 167
 
168 168
     /**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param string $path
172 172
      * @return mixed
173 173
      */
174
-    public function save($data, $path='') {
174
+    public function save($data, $path = '') {
175 175
         $path   = \arc\path::collapse($path, $this->path);
176 176
         $parent = ($path=='/' ? '' : \arc\path::parent($path));
177 177
         if ($path!='/' && !$this->exists($parent)) {
Please login to merge, or discard this patch.
src/store/PSQLQueryParser.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,11 +4,11 @@
 block discarded – undo
4 4
 
5 5
 final class PSQLQueryParser {
6 6
 	
7
-	private $tokenizer;
7
+    private $tokenizer;
8 8
 
9
-	public function __construct($tokenizer) {
10
-		$this->tokenizer = $tokenizer;
11
-	}
9
+    public function __construct($tokenizer) {
10
+        $this->tokenizer = $tokenizer;
11
+    }
12 12
 
13 13
     /**
14 14
      * @param string $query
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
         $position = 0;
24 24
         $expect   = 'name|parenthesis_open|not';
25 25
 
26
-        foreach( call_user_func($this->tokenizer, $query) as $token ) {
26
+        foreach (call_user_func($this->tokenizer, $query) as $token) {
27 27
             $type = key($token);
28
-            list($token, $offset)=$token[$type];
29
-            if ( !preg_match("/^$expect$/",$type) ) {
28
+            list($token, $offset) = $token[$type];
29
+            if (!preg_match("/^$expect$/", $type)) {
30 30
                 throw new \LogicException('Parse error at '.$position.': expected '.$expect.', got '.$type.': '
31
-                    .(substr($query,0, $position)." --> ".substr($query,$position)) );
31
+                    .(substr($query, 0, $position)." --> ".substr($query, $position)));
32 32
             }
33
-            switch($type) {
33
+            switch ($type) {
34 34
                 case 'number':
35 35
                 case 'string':
36 36
                     $sql   .= $part.$token;
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
                             $part = $token;
48 48
                         break;
49 49
                         default:
50
-                            $part = "nodes.data #>> '{".str_replace('.',',',$token)."}'";
50
+                            $part = "nodes.data #>> '{".str_replace('.', ',', $token)."}'";
51 51
                         break;
52 52
                     }
53 53
                     $expect = 'compare';
54 54
                 break;
55 55
                 case 'compare':
56
-                    switch( $token ) {
56
+                    switch ($token) {
57 57
                         case '>':
58 58
                         case '>=':
59 59
                         case '<':
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
                         case '=':
62 62
                         case '<>':
63 63
                         case '!=':
64
-                            $part.=$token;
64
+                            $part .= $token;
65 65
                         break;
66 66
                         case '?':
67
-                            $part.=$token;
67
+                            $part .= $token;
68 68
                             str_replace($part, '#>>', '#>');
69 69
                         break;
70 70
                         case '~=':
71
-                            $part.=' like ';
71
+                            $part .= ' like ';
72 72
                         break;
73 73
                         case '!~':
74
-                            $part.=' not like ';
74
+                            $part .= ' not like ';
75 75
                         break;
76 76
                     }
77 77
                     $expect = 'number|string';
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                 case 'parenthesis_close':
93 93
                     $sql .= $token;
94 94
                     $indent--;
95
-                    if ( $indent>0 ) {
95
+                    if ($indent>0) {
96 96
                         $expect = 'operator|parenthesis_close';
97 97
                     } else {
98 98
                         $expect = 'operator';
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
             }
102 102
             $position += $offset + strlen($token);
103 103
         }
104
-        if ( $indent!=0 ) {
104
+        if ($indent!=0) {
105 105
             throw new \LogicException('unbalanced parenthesis');
106
-        } else if ( trim($part) ) {
106
+        } else if (trim($part)) {
107 107
             $position -= strlen($token);
108
-            throw new \LogicException('parse error at '.$position.': '.(substr($query,0, $position)." --> ".substr($query,$position)));
108
+            throw new \LogicException('parse error at '.$position.': '.(substr($query, 0, $position)." --> ".substr($query, $position)));
109 109
         } else {
110 110
             return $sql;
111 111
         }
Please login to merge, or discard this patch.
src/store/MySQLQueryParser.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@
 block discarded – undo
6 6
 
7 7
     private $tokenizer;
8 8
 
9
-	public function __construct($tokenizer) {
10
-		$this->tokenizer = $tokenizer;
11
-	}
9
+    public function __construct($tokenizer) {
10
+        $this->tokenizer = $tokenizer;
11
+    }
12 12
 
13 13
     /**
14 14
      * @param string $query
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
         $position = 0;
24 24
         $expect   = 'name|parenthesis_open|not';
25 25
         
26
-        foreach( call_user_func($this->tokenizer, $query) as $token ) {
26
+        foreach (call_user_func($this->tokenizer, $query) as $token) {
27 27
             $type = key($token);
28
-            list($token, $offset)=$token[$type];
29
-            if ( !preg_match("/^$expect$/",$type) ) {
28
+            list($token, $offset) = $token[$type];
29
+            if (!preg_match("/^$expect$/", $type)) {
30 30
                 throw new \LogicException('Parse error at '.$position.': expected '.$expect.', got '.$type.': '
31
-                    .(substr($query,0, $position)." --> ".substr($query,$position)) );
31
+                    .(substr($query, 0, $position)." --> ".substr($query, $position)));
32 32
             }
33
-            switch($type) {
33
+            switch ($type) {
34 34
                 case 'number':
35 35
                 case 'string':
36 36
                     $sql   .= $part.$token;
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
                     $expect = 'compare';
54 54
                 break;
55 55
                 case 'compare':
56
-                    switch( $token ) {
56
+                    switch ($token) {
57 57
                         case '>':
58 58
                         case '>=':
59 59
                         case '<':
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
                         case '=':
62 62
                         case '<>':
63 63
                         case '!=':
64
-                            $part.=$token;
64
+                            $part .= $token;
65 65
                         break;
66 66
                         case '?':
67
-                            $part.= ' IS NOT NULL';
67
+                            $part .= ' IS NOT NULL';
68 68
                             str_replace($part, '->>', '->');
69 69
                         break;
70 70
                         case '~=':
71
-                            $part.=' like ';
71
+                            $part .= ' like ';
72 72
                         break;
73 73
                         case '!~':
74
-                            $part.=' not like ';
74
+                            $part .= ' not like ';
75 75
                         break;
76 76
                     }
77 77
                     $expect = 'number|string';
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                 case 'parenthesis_close':
93 93
                     $sql .= $token;
94 94
                     $indent--;
95
-                    if ( $indent>0 ) {
95
+                    if ($indent>0) {
96 96
                         $expect = 'operator|parenthesis_close';
97 97
                     } else {
98 98
                         $expect = 'operator';
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
             }
102 102
             $position += $offset + strlen($token);
103 103
         }
104
-        if ( $indent!=0 ) {
104
+        if ($indent!=0) {
105 105
             throw new \LogicException('unbalanced parenthesis');
106
-        } else if ( trim($part) ) {
106
+        } else if (trim($part)) {
107 107
             $position -= strlen($token);
108
-            throw new \LogicException('parse error at '.$position.': '.(substr($query,0, $position)." --> ".substr($query,$position)));
108
+            throw new \LogicException('parse error at '.$position.': '.(substr($query, 0, $position)." --> ".substr($query, $position)));
109 109
         } else {
110 110
             return $sql;
111 111
         }
Please login to merge, or discard this patch.
src/store/MySQLStore.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function cd($path)
35 35
     {
36
-        return new self( $this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path) );
36
+        return new self($this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path));
37 37
     }
38 38
 
39 39
     /**
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
      * @param string $path
43 43
      * @return mixed
44 44
      */
45
-    public function find($query, $path='')
45
+    public function find($query, $path = '')
46 46
     {
47 47
         $path = \arc\path::collapse($path, $this->path);
48 48
         $sql  = $this->queryParser->parse($query, $path);
49
-        return ($this->resultHandler)( $sql, [] );
49
+        return ($this->resultHandler)($sql, []);
50 50
     }
51 51
 
52 52
     /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @param string $path
55 55
      * @return mixed
56 56
      */
57
-    public function get($path='')
57
+    public function get($path = '')
58 58
     {
59 59
         $path   = \arc\path::collapse($path, $this->path);
60 60
         $parent = ($path=='/' ? '' : \arc\path::parent($path));
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
      * @param string $top
76 76
      * @return mixed
77 77
      */
78
-    public function parents($path='', $top='/')
78
+    public function parents($path = '', $top = '/')
79 79
     {
80
-        $path   = \arc\path::collapse($path, $this->path);
80
+        $path = \arc\path::collapse($path, $this->path);
81 81
         return ($this->resultHandler)(
82 82
             /** @lang sql */
83 83
             'path=substring(:path,1,length(path)) '
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      * @param string $path
92 92
      * @return mixed
93 93
      */
94
-    public function ls($path='')
94
+    public function ls($path = '')
95 95
     {
96
-        $path   = \arc\path::collapse($path, $this->path);
96
+        $path = \arc\path::collapse($path, $this->path);
97 97
         return ($this->resultHandler)('parent=:path', [':path' => $path]);
98 98
     }
99 99
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param string $path
103 103
      * @return bool
104 104
      */
105
-    public function exists($path='')
105
+    public function exists($path = '')
106 106
     {
107 107
         $path   = \arc\path::collapse($path, $this->path);
108 108
         $query  = $this->db->prepare('select count(*) from nodes where path=:path');
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function initialize() {
118 118
         try {
119
-            if ($result=$this->exists('/')) {
119
+            if ($result = $this->exists('/')) {
120 120
                 return false;
121 121
             }
122 122
         } catch (\PDOException $e) {
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 SQL;
141 141
 //        $queries[] = "create trigger before_insert_node before insert on nodes for each row set new.id = UUID_TO_BIN(uuid());";
142 142
         $queries[] = "create unique index path on nodes ( path(255) );";
143
-        foreach ( $queries as $query ) {
143
+        foreach ($queries as $query) {
144 144
             $result = $this->db->exec($query);
145 145
             if ($result===false) {
146 146
                 $this->db->exec('rollback;');
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 
152 152
         return $this->save(\arc\prototype::create([
153 153
             'name' => 'Root'
154
-        ]),'/');
154
+        ]), '/');
155 155
     }
156 156
 
157 157
     /**
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
      * @param string $path
161 161
      * @return mixed
162 162
      */
163
-    public function save($data, $path='') {
163
+    public function save($data, $path = '') {
164 164
         $path   = \arc\path::collapse($path, $this->path);
165 165
         $parent = ($path=='/' ? '' : \arc\path::parent($path));
166 166
         if ($path!='/' && !$this->exists($parent)) {
Please login to merge, or discard this patch.
src/store.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
      * @param string $resultHandler handler that executes the sql query
20 20
      * @return store\Store the store
21 21
      */
22
-    public static function connect($dsn, $resultHandler=null)
22
+    public static function connect($dsn, $resultHandler = null)
23 23
     {
24 24
         $db = new \PDO($dsn);
25 25
         $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
         $className = $storeType.'Store';
41 41
         $store = new $className(
42 42
             $db, 
43
-            new $queryParserClassName(array('\arc\store','tokenizer')), 
43
+            new $queryParserClassName(array('\arc\store', 'tokenizer')), 
44 44
             $resultHandler($db)
45 45
         );
46 46
 
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
                     }, ARRAY_FILTER_USE_KEY
187 187
                 );
188 188
             }
189
-        } while($result);
190
-        if ( trim($query) ) {
189
+        } while ($result);
190
+        if (trim($query)) {
191 191
             throw new \LogicException('Could not parse '.$query);
192 192
         }
193 193
     }
Please login to merge, or discard this patch.
src/store/Store.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
      * @param string $path
16 16
      * @return mixed
17 17
      */
18
-    public function find($query, $path='');
18
+    public function find($query, $path = '');
19 19
 
20 20
     /**
21 21
      * get a single object from the store by path
22 22
      * @param string $path
23 23
      * @return mixed
24 24
      */
25
-    public function get($path='');
25
+    public function get($path = '');
26 26
 
27 27
     /**
28 28
      * list all parents, including self, by path, starting from the root
@@ -30,21 +30,21 @@  discard block
 block discarded – undo
30 30
      * @param string $top
31 31
      * @return mixed
32 32
      */
33
-    public function parents($path='', $top='/');
33
+    public function parents($path = '', $top = '/');
34 34
 
35 35
     /**
36 36
      * list all child objects by path
37 37
      * @param string $path
38 38
      * @return mixed
39 39
      */
40
-    public function ls($path='');
40
+    public function ls($path = '');
41 41
 
42 42
     /**
43 43
      * returns true if an object with the given path exists
44 44
      * @param string $path
45 45
      * @return bool
46 46
      */
47
-    public function exists($path='');
47
+    public function exists($path = '');
48 48
 
49 49
     /**
50 50
      * initialize the store, if it wasn't before
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      * @param string $path
59 59
      * @return mixed
60 60
      */
61
-    public function save($data, $path='');
61
+    public function save($data, $path = '');
62 62
 
63 63
     /**
64 64
      * remove the object with the given path and all its children
Please login to merge, or discard this patch.
src/store/ResultHandlers.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
                 $q = $db->prepare('select * from nodes where '.$query);
12 12
                 $result = $q->execute($args);
13 13
                 $dataset = [];
14
-                while ( $data = $q->fetch(\PDO::FETCH_ASSOC) ) {
14
+                while ($data = $q->fetch(\PDO::FETCH_ASSOC)) {
15 15
                     $value = (object) $data;
16 16
                     $value->data = json_decode($value->data);
17 17
                     $value->ctime = strtotime($value->ctime);
Please login to merge, or discard this patch.