Skip to content

Commit 45bd0d1

Browse files
authored
.php-cs-fixer.php: use PSR12 instead of Symfony (#160)
* .php-cs-fixer.php: use PSR12 instead of Symfony Symfony rules are constantly changing and lead to false-positives. PSR12 is more stable. * coding style fixes; removed some commented out code
1 parent e7ac9c2 commit 45bd0d1

14 files changed

+73
-96
lines changed

.php-cs-fixer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
->setFinder($finder)
2121
->setRiskyAllowed(true)
2222
->setRules([
23-
'@Symfony' => true,
24-
'@Symfony:risky' => true,
23+
'@PSR12' => true,
2524
'phpdoc_summary' => false,
2625
])
2726
;

ARC2.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,8 @@ public static function getStructType($v)
369369
if (in_array('p', array_keys($v[0]))) {
370370
return 'triples';
371371
}
372-
}
373-
/* associative array */
374-
else {
372+
} else {
373+
/* associative array */
375374
/* index */
376375
foreach ($v as $s => $ps) {
377376
if (!is_array($ps)) {

ARC2_Reader.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,8 @@ public function readStream($buffer_xml = true, $d_size = 1024)
423423
/* data */
424424
if ('data' == $s_type) {
425425
$d = ($d_size > 0) ? substr($s['data'], $s['pos'], $d_size) : '';
426-
}
427-
/* socket */
428-
elseif ('socket' == $s_type) {
426+
} elseif ('socket' == $s_type) {
427+
/* socket */
429428
$d = ($d_size > 0) && !feof($s['socket']) ? fread($s['socket'], $d_size) : '';
430429
}
431430
$eof = $d ? false : true;

extractors/ARC2_RdfaExtractor.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ public function processNode($n, $ct, $level)
9696
} /* patch by masaka */
9797
}
9898
}
99-
}
100-
/* step 5 */
101-
else {
99+
} else {
100+
/* step 5 */
102101
foreach (['about', 'src'] as $attr) {
103102
if (isset($n['a'][$attr]) && (list($uri, $sub_v) = $this->xURI($n['a'][$attr], $lct['base'], $lct['ns'], '', $lct)) && $uri) {
104103
$lct['new_s'] = $uri;

parsers/ARC2_AtomParser.php

+12-18
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,16 @@ public function extractProps($els, $container)
173173
/* content handling */
174174
if (in_array($k, [$this->rss.'description', $this->content.'encoded'])) {
175175
$v = $this->getNodeContent($info);
176-
}
177-
/* source handling */
178-
elseif ($k == $this->dc.'source') {
176+
} elseif ($k == $this->dc.'source') {
177+
/* source handling */
179178
$sub_nodes = $this->node_index[$info['id']];
180179
foreach ($sub_nodes as $sub_pos => $sub_info) {
181180
if ('id' == $sub_info['tag']) {
182181
$v = trim($sub_info['cdata']);
183182
}
184183
}
185-
}
186-
/* link handling */
187-
elseif ($k == $this->rss.'link') {
184+
} elseif ($k == $this->rss.'link') {
185+
/* link handling */
188186
if ($link_type = $this->v('type', '', $info['a'])) {
189187
$k2 = $this->dc.'format';
190188
if (!isset($sub_index[$v])) {
@@ -195,9 +193,8 @@ public function extractProps($els, $container)
195193
}
196194
$sub_index[$v][$k2][] = ['value' => $link_type, 'type' => 'literal'];
197195
}
198-
}
199-
/* author handling */
200-
elseif ($k == $this->dc.'creator') {
196+
} elseif ($k == $this->dc.'creator') {
197+
/* author handling */
201198
$sub_nodes = $this->node_index[$info['id']];
202199
foreach ($sub_nodes as $sub_pos => $sub_info) {
203200
if ('name' == $sub_info['tag']) {
@@ -212,21 +209,18 @@ public function extractProps($els, $container)
212209
$r[$k2][] = ['value' => $v2, 'type' => 'uri'];
213210
}
214211
}
215-
}
216-
/* date handling */
217-
elseif (in_array($k, [$this->dc.'date', $this->dct.'modified'])) {
212+
} elseif (in_array($k, [$this->dc.'date', $this->dct.'modified'])) {
213+
/* date handling */
218214
if (!preg_match('/^[0-9]{4}/', $v) && ($sub_v = strtotime($v)) && (-1 != $sub_v)) {
219215
$tz = date('Z', $sub_v); /* timezone offset */
220216
$sub_v -= $tz; /* utc */
221217
$v = date('Y-m-d\TH:i:s\Z', $sub_v);
222218
}
223-
}
224-
/* tag handling */
225-
elseif ($k == $this->dc.'subject') {
219+
} elseif ($k == $this->dc.'subject') {
220+
/* tag handling */
226221
$v = $this->v('term', '', $info['a']);
227-
}
228-
/* other attributes in closed tags */
229-
elseif (!$v && ('closed' == $info['state']) && $info['a']) {
222+
} elseif (!$v && ('closed' == $info['state']) && $info['a']) {
223+
/* other attributes in closed tags */
230224
foreach ($info['a'] as $sub_k => $sub_v) {
231225
if (!preg_match('/(xmlns|\:|type)/', $sub_k)) {
232226
$v = $sub_v;

parsers/ARC2_CBJSONParser.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,21 @@ public function extractResourceRDF($struct, $s, $pos = 0)
163163
if ('name' == $k) {
164164
$this->addT($s, 'http://www.w3.org/2000/01/rdf-schema#label', $v, $s_type, $o_type);
165165
}
166-
}
167-
/* structured, single v */
168-
elseif (!$this->isFlatArray($v)) {
169-
if ($o_type = $this->getStructType($v, $k)) {/* known type */
166+
} elseif (!$this->isFlatArray($v)) {
167+
/* structured, single v */
168+
if ($o_type = $this->getStructType($v, $k)) {
169+
/* known type */
170170
$o = $this->getResourceID($v, $o_type);
171171
$this->addT($s, $p, $o, $s_type, 'uri');
172172
$this->addT($o, $this->rdf.'type', $this->default_ns.$this->camelCase($o_type), 'uri', 'uri');
173-
} else {/* unknown type */
173+
} else {
174+
/* unknown type */
174175
$o = $this->createSubURI($s, $k, $pos);
175176
$this->addT($s, $p, $o, $s_type, 'uri');
176177
$this->extractResourceRDF($v, $o);
177178
}
178-
}
179-
/* value list */
180-
else {
179+
} else {
180+
/* value list */
181181
foreach ($v as $sub_pos => $sub_v) {
182182
$this->extractResourceRDF([$k => $sub_v], $s, $sub_pos);
183183
}

parsers/ARC2_JSONParser.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ public function extractObject($v)
7474
if ($sub_r = $this->x('\}', $v)) {
7575
$v = $sub_r[1];
7676
}
77-
}
78-
/* sub-list */
79-
elseif ($sub_r = $this->x('\[', $v)) {
77+
} elseif ($sub_r = $this->x('\[', $v)) {
78+
/* sub-list */
8079
$v = $sub_r[1];
8180
while ((list($sub_r, $v) = $this->extractObject($v)) && $sub_r) {
8281
$r[] = $sub_r;
@@ -85,9 +84,8 @@ public function extractObject($v)
8584
if ($sub_r = $this->x('\]', $v)) {
8685
$v = $sub_r[1];
8786
}
88-
}
89-
/* sub-value */
90-
elseif ((list($sub_r, $v) = $this->extractValue($v)) && (false !== $sub_r)) {
87+
} elseif ((list($sub_r, $v) = $this->extractValue($v)) && (false !== $sub_r)) {
88+
/* sub-value */
9189
$r = $sub_r;
9290
}
9391

@@ -136,7 +134,6 @@ public function extractValue($v)
136134
$val = preg_replace_callback('/\\\u(.{4})/', function ($matches) {
137135
return chr(hexdec($matches[1]));
138136
}, $val);
139-
// $val = preg_replace_callback('/\\\u00(.{2})', function($matches) { return rawurldecode("%" . $matches[1]); }, $val);
140137
/* other escaped chars */
141138
$from = ['\\\\', '\r', '\t', '\n', '\"', '\b', '\f', '\/'];
142139
$to = ['\\', "\r", "\t", "\n", '"', "\b", "\f", '/'];
@@ -167,7 +164,6 @@ public function countTriples()
167164
public function addT($s = '', $p = '', $o = '', $s_type = '', $o_type = '', $o_dt = '', $o_lang = '')
168165
{
169166
$o = $this->toUTF8($o);
170-
// echo str_replace($this->base, '', "-----\n adding $s / $p / $o\n-----\n");
171167
$t = ['s' => $s, 'p' => $p, 'o' => $o, 's_type' => $s_type, 'o_type' => $o_type, 'o_datatype' => $o_dt, 'o_lang' => $o_lang];
172168
if ($this->skip_dupes) {
173169
$h = md5(serialize($t));

parsers/ARC2_RDFXMLParser.php

+18-22
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,12 @@ public function h1Open($t, $a)
277277
if (isset($a[$this->rdf.'ID'])) {
278278
$s['type'] = 'uri';
279279
$s['value'] = $this->calcURI('#'.$a[$this->rdf.'ID'], $s['x_base']);
280-
}
281-
/* about */
282-
elseif (isset($a[$this->rdf.'about'])) {
280+
} elseif (isset($a[$this->rdf.'about'])) {
281+
/* about */
283282
$s['type'] = 'uri';
284283
$s['value'] = $this->calcURI($a[$this->rdf.'about'], $s['x_base']);
285-
}
286-
/* bnode */
287-
else {
284+
} else {
285+
/* bnode */
288286
$s['type'] = 'bnode';
289287
if (isset($a[$this->rdf.'nodeID'])) {
290288
$s['value'] = '_:'.$a[$this->rdf.'nodeID'];
@@ -301,16 +299,14 @@ public function h1Open($t, $a)
301299
$this->addT($sup_s['value'], $sup_s['p'], $coll['value'], $sup_s['type'], $coll['type']);
302300
$this->addT($coll['value'], $this->rdf.'first', $s['value'], $coll['type'], $s['type']);
303301
$this->pushS($coll);
304-
}
305-
/* new entry in existing coll */
306-
elseif (isset($sup_s['is_coll']) && $sup_s['is_coll']) {
302+
} elseif (isset($sup_s['is_coll']) && $sup_s['is_coll']) {
303+
/* new entry in existing coll */
307304
$coll = ['value' => $this->createBnodeID(), 'type' => 'bnode', 'is_coll' => true, 'x_base' => $s['x_base'], 'x_lang' => $s['x_lang']];
308305
$this->addT($sup_s['value'], $this->rdf.'rest', $coll['value'], $sup_s['type'], $coll['type']);
309306
$this->addT($coll['value'], $this->rdf.'first', $s['value'], $coll['type'], $s['type']);
310307
$this->pushS($coll);
311-
}
312-
/* normal sub-node */
313-
elseif (isset($sup_s['p']) && $sup_s['p']) {
308+
} elseif (isset($sup_s['p']) && $sup_s['p']) {
309+
/* normal sub-node */
314310
$this->addT($sup_s['value'], $sup_s['p'], $s['value'], $sup_s['type'], $s['type']);
315311
}
316312
}
@@ -328,7 +324,10 @@ public function h1Open($t, $a)
328324
}
329325
/* any other attrs (skip rdf and xml, except rdf:_, rdf:value, rdf:Seq) */
330326
foreach ($a as $k => $v) {
331-
if (((!str_contains($k, $this->xml)) && (!str_contains($k, $this->rdf))) || preg_match('/(\_[0-9]+|value|Seq|Bag|Alt|Statement|Property|List)$/', $k)) {
327+
if (
328+
((!str_contains($k, $this->xml)) && (!str_contains($k, $this->rdf)))
329+
|| preg_match('/(\_[0-9]+|value|Seq|Bag|Alt|Statement|Property|List)$/', $k)
330+
) {
332331
if (strpos($k, ':')) {
333332
$this->addT($s['value'], $k, $v, $s['type'], 'literal', '', $s['x_lang']);
334333
}
@@ -385,9 +384,8 @@ public function h2Open($t, $a)
385384
unset($s['p_id']);
386385
}
387386
$this->state = 3;
388-
}
389-
/* named bnode */
390-
elseif (isset($a[$this->rdf.'nodeID'])) {
387+
} elseif (isset($a[$this->rdf.'nodeID'])) {
388+
/* named bnode */
391389
$o['value'] = '_:'.$a[$this->rdf.'nodeID'];
392390
$o['type'] = 'bnode';
393391
$this->addT($s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
@@ -396,9 +394,8 @@ public function h2Open($t, $a)
396394
if (isset($s['p_id'])) {
397395
$this->reify($this->calcURI('#'.$s['p_id'], $b), $s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
398396
}
399-
}
400-
/* parseType */
401-
elseif (isset($a[$this->rdf.'parseType'])) {
397+
} elseif (isset($a[$this->rdf.'parseType'])) {
398+
/* parseType */
402399
if ('Literal' === $a[$this->rdf.'parseType']) {
403400
$s['o_xml_level'] = 0;
404401
$s['o_xml_data'] = '';
@@ -421,9 +418,8 @@ public function h2Open($t, $a)
421418
$s['o_is_coll'] = true;
422419
$this->state = 4;
423420
}
424-
}
425-
/* sub-node or literal */
426-
else {
421+
} else {
422+
/* sub-node or literal */
427423
$s['o_cdata'] = '';
428424
if (isset($a[$this->rdf.'datatype'])) {
429425
$s['o_datatype'] = $a[$this->rdf.'datatype'];

parsers/ARC2_SPARQLParser.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,8 @@ public function xIRI_REF($v)
837837
return [$r[1], $r[2]];
838838
} elseif ($r = $this->x('\<([^\<\>\s\"\|\^`]*)\>', $v)) {
839839
return [$r[1] ? $r[1] : true, $r[2]];
840-
}
841-
/* allow reserved chars in obvious IRIs */
842-
elseif ($r = $this->x('\<(https?\:[^\s][^\<\>]*)\>', $v)) {
840+
} elseif ($r = $this->x('\<(https?\:[^\s][^\<\>]*)\>', $v)) {
841+
/* allow reserved chars in obvious IRIs */
843842
return [$r[1] ? $r[1] : true, $r[2]];
844843
}
845844

store/ARC2_RemoteStore.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ public function runQuery($q, $qt = '', $infos = '')
157157
$mappings = ['rdfxml' => 'RDFXML', 'sparqlxml' => 'SPARQLXMLResult', 'turtle' => 'Turtle'];
158158
if (!$format || !isset($mappings[$format])) {
159159
return $resp;
160-
// return $this->addError('No parser available for "' . $format . '" SPARQL result');
161160
}
162161
/* format parser */
163162
$suffix = $mappings[$format].'Parser';
@@ -173,15 +172,13 @@ public function runQuery($q, $qt = '', $infos = '')
173172
} else {
174173
$r = $bid;
175174
}
176-
}
177-
/* select */
178-
elseif (('select' == $qt) && !method_exists($parser, 'getRows')) {
175+
} elseif (('select' == $qt) && !method_exists($parser, 'getRows')) {
176+
/* select */
179177
$r = $resp;
180178
} elseif ('select' == $qt) {
181179
$r = ['rows' => $parser->getRows(), 'variables' => $parser->getVariables()];
182-
}
183-
/* any other */
184-
else {
180+
} else {
181+
/* any other */
185182
$r = $parser->getSimpleIndex(0);
186183
}
187184
unset($parser);

store/ARC2_Store.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,8 @@ public function getTermID($val, $term = '')
711711
}
712712
}
713713
}
714-
}
715-
/* exact match */
716-
else {
714+
} else {
715+
/* exact match */
717716
$sql = 'SELECT id
718717
FROM '.$this->getTablePrefix().$tbl."
719718
WHERE val = BINARY '".$this->db->escape($val)."'

store/ARC2_StoreDeleteQueryHandler.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ public function runQuery($infos)
3939
/* graph(s) only */
4040
if (!$this->v('construct_triples', [], $this->infos['query'])) {
4141
$tc = $this->deleteTargetGraphs();
42-
}
43-
/* graph(s) + explicit triples */
44-
elseif (!$this->v('pattern', [], $this->infos['query'])) {
42+
} elseif (!$this->v('pattern', [], $this->infos['query'])) {
43+
/* graph(s) + explicit triples */
4544
$tc = $this->deleteTriples();
46-
}
47-
/* graph(s) + constructed triples */
48-
else {
45+
} else {
46+
/* graph(s) + constructed triples */
4947
$tc = $this->deleteConstructedGraph();
5048
}
5149
$t2 = ARC2::mtime();

store/ARC2_StoreLoadQueryHandler.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ public function getStoredTermID($val, $type_id, $tbl)
282282
$tbl_prefix = $this->store->getTablePrefix();
283283
$sub_tbls = ('id' == $tbl)
284284
? ['id2val', 's2val', 'o2val']
285-
: ('s' == $tbl
285+
: (
286+
's' == $tbl
286287
? ['s2val', 'id2val', 'o2val']
287288
: ['o2val', 'id2val', 's2val']
288289
);

store/ARC2_StoreSelectQueryHandler.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,8 @@ public function getGraphInfos($id)
419419
}
420420

421421
return array_merge($this->getGraphInfos($pattern['parent_id']), $r);
422-
}
423-
/* FROM / FROM NAMED */
424-
else {
422+
} else {
423+
/* FROM / FROM NAMED */
425424
if (isset($this->infos['query']['dataset'])) {
426425
foreach ($this->infos['query']['dataset'] as $set) {
427426
$r[] = array_merge(['type' => 'dataset'], $set);
@@ -548,14 +547,16 @@ public function getQuerySQL()
548547
return ''.(
549548
$this->is_union_query
550549
? 'SELECT'
551-
: 'SELECT'.$this->getDistinctSQL()).$nl.
550+
: 'SELECT'.$this->getDistinctSQL()
551+
).$nl.
552552
$this->getResultVarsSQL().$nl. /* fills $index['sub_joins'] */
553553
$this->getFROMSQL().
554554
$this->getAllJoinsSQL().
555555
$this->getWHERESQL().
556556
$this->getGROUPSQL().
557557
$this->getORDERSQL().
558-
($this->is_union_query
558+
(
559+
$this->is_union_query
559560
? ''
560561
: $this->getLIMITSQL()
561562
).$nl.'';
@@ -608,9 +609,8 @@ public function getResultVarsSQL()
608609
$r .= $var['aggregate'].'('.$conv_code.$distinct_code.$tbl_alias.') AS `'.$var['alias'].'`';
609610
$added[$var['alias']] = 1;
610611
}
611-
}
612-
/* normal var */
613-
else {
612+
} else {
613+
/* normal var */
614614
if (!isset($added[$var_name])) {
615615
$r .= $r ? ','.$nl.' ' : ' ';
616616
$r .= $tbl_alias.' AS `'.$var_name.'`';
@@ -1216,7 +1216,8 @@ public function getFilterPatternSQL($pattern, $context)
12161216
/* some really ugly tweaks */
12171217
/* empty language filter: FILTER ( lang(?v) = '' ) */
12181218
$r = preg_replace(
1219-
'/\(\/\* language call \*\/ ([^\s]+) = ""\)/s', '((\\1 = "") OR (\\1 LIKE "%:%"))',
1219+
'/\(\/\* language call \*\/ ([^\s]+) = ""\)/s',
1220+
'((\\1 = "") OR (\\1 LIKE "%:%"))',
12201221
$r
12211222
);
12221223

0 commit comments

Comments
 (0)