Skip to content

Commit

Permalink
.php-cs-fixer.php: use PSR12 instead of Symfony (#160)
Browse files Browse the repository at this point in the history
* .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
  • Loading branch information
k00ni authored Nov 22, 2024
1 parent e7ac9c2 commit 45bd0d1
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 96 deletions.
3 changes: 1 addition & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PSR12' => true,
'phpdoc_summary' => false,
])
;
Expand Down
5 changes: 2 additions & 3 deletions ARC2.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,8 @@ public static function getStructType($v)
if (in_array('p', array_keys($v[0]))) {
return 'triples';
}
}
/* associative array */
else {
} else {
/* associative array */
/* index */
foreach ($v as $s => $ps) {
if (!is_array($ps)) {
Expand Down
5 changes: 2 additions & 3 deletions ARC2_Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,8 @@ public function readStream($buffer_xml = true, $d_size = 1024)
/* data */
if ('data' == $s_type) {
$d = ($d_size > 0) ? substr($s['data'], $s['pos'], $d_size) : '';
}
/* socket */
elseif ('socket' == $s_type) {
} elseif ('socket' == $s_type) {
/* socket */
$d = ($d_size > 0) && !feof($s['socket']) ? fread($s['socket'], $d_size) : '';
}
$eof = $d ? false : true;
Expand Down
5 changes: 2 additions & 3 deletions extractors/ARC2_RdfaExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ public function processNode($n, $ct, $level)
} /* patch by masaka */
}
}
}
/* step 5 */
else {
} else {
/* step 5 */
foreach (['about', 'src'] as $attr) {
if (isset($n['a'][$attr]) && (list($uri, $sub_v) = $this->xURI($n['a'][$attr], $lct['base'], $lct['ns'], '', $lct)) && $uri) {
$lct['new_s'] = $uri;
Expand Down
30 changes: 12 additions & 18 deletions parsers/ARC2_AtomParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,16 @@ public function extractProps($els, $container)
/* content handling */
if (in_array($k, [$this->rss.'description', $this->content.'encoded'])) {
$v = $this->getNodeContent($info);
}
/* source handling */
elseif ($k == $this->dc.'source') {
} elseif ($k == $this->dc.'source') {
/* source handling */
$sub_nodes = $this->node_index[$info['id']];
foreach ($sub_nodes as $sub_pos => $sub_info) {
if ('id' == $sub_info['tag']) {
$v = trim($sub_info['cdata']);
}
}
}
/* link handling */
elseif ($k == $this->rss.'link') {
} elseif ($k == $this->rss.'link') {
/* link handling */
if ($link_type = $this->v('type', '', $info['a'])) {
$k2 = $this->dc.'format';
if (!isset($sub_index[$v])) {
Expand All @@ -195,9 +193,8 @@ public function extractProps($els, $container)
}
$sub_index[$v][$k2][] = ['value' => $link_type, 'type' => 'literal'];
}
}
/* author handling */
elseif ($k == $this->dc.'creator') {
} elseif ($k == $this->dc.'creator') {
/* author handling */
$sub_nodes = $this->node_index[$info['id']];
foreach ($sub_nodes as $sub_pos => $sub_info) {
if ('name' == $sub_info['tag']) {
Expand All @@ -212,21 +209,18 @@ public function extractProps($els, $container)
$r[$k2][] = ['value' => $v2, 'type' => 'uri'];
}
}
}
/* date handling */
elseif (in_array($k, [$this->dc.'date', $this->dct.'modified'])) {
} elseif (in_array($k, [$this->dc.'date', $this->dct.'modified'])) {
/* date handling */
if (!preg_match('/^[0-9]{4}/', $v) && ($sub_v = strtotime($v)) && (-1 != $sub_v)) {
$tz = date('Z', $sub_v); /* timezone offset */
$sub_v -= $tz; /* utc */
$v = date('Y-m-d\TH:i:s\Z', $sub_v);
}
}
/* tag handling */
elseif ($k == $this->dc.'subject') {
} elseif ($k == $this->dc.'subject') {
/* tag handling */
$v = $this->v('term', '', $info['a']);
}
/* other attributes in closed tags */
elseif (!$v && ('closed' == $info['state']) && $info['a']) {
} elseif (!$v && ('closed' == $info['state']) && $info['a']) {
/* other attributes in closed tags */
foreach ($info['a'] as $sub_k => $sub_v) {
if (!preg_match('/(xmlns|\:|type)/', $sub_k)) {
$v = $sub_v;
Expand Down
16 changes: 8 additions & 8 deletions parsers/ARC2_CBJSONParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,21 @@ public function extractResourceRDF($struct, $s, $pos = 0)
if ('name' == $k) {
$this->addT($s, 'http://www.w3.org/2000/01/rdf-schema#label', $v, $s_type, $o_type);
}
}
/* structured, single v */
elseif (!$this->isFlatArray($v)) {
if ($o_type = $this->getStructType($v, $k)) {/* known type */
} elseif (!$this->isFlatArray($v)) {
/* structured, single v */
if ($o_type = $this->getStructType($v, $k)) {
/* known type */
$o = $this->getResourceID($v, $o_type);
$this->addT($s, $p, $o, $s_type, 'uri');
$this->addT($o, $this->rdf.'type', $this->default_ns.$this->camelCase($o_type), 'uri', 'uri');
} else {/* unknown type */
} else {
/* unknown type */
$o = $this->createSubURI($s, $k, $pos);
$this->addT($s, $p, $o, $s_type, 'uri');
$this->extractResourceRDF($v, $o);
}
}
/* value list */
else {
} else {
/* value list */
foreach ($v as $sub_pos => $sub_v) {
$this->extractResourceRDF([$k => $sub_v], $s, $sub_pos);
}
Expand Down
12 changes: 4 additions & 8 deletions parsers/ARC2_JSONParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public function extractObject($v)
if ($sub_r = $this->x('\}', $v)) {
$v = $sub_r[1];
}
}
/* sub-list */
elseif ($sub_r = $this->x('\[', $v)) {
} elseif ($sub_r = $this->x('\[', $v)) {
/* sub-list */
$v = $sub_r[1];
while ((list($sub_r, $v) = $this->extractObject($v)) && $sub_r) {
$r[] = $sub_r;
Expand All @@ -85,9 +84,8 @@ public function extractObject($v)
if ($sub_r = $this->x('\]', $v)) {
$v = $sub_r[1];
}
}
/* sub-value */
elseif ((list($sub_r, $v) = $this->extractValue($v)) && (false !== $sub_r)) {
} elseif ((list($sub_r, $v) = $this->extractValue($v)) && (false !== $sub_r)) {
/* sub-value */
$r = $sub_r;
}

Expand Down Expand Up @@ -136,7 +134,6 @@ public function extractValue($v)
$val = preg_replace_callback('/\\\u(.{4})/', function ($matches) {
return chr(hexdec($matches[1]));
}, $val);
// $val = preg_replace_callback('/\\\u00(.{2})', function($matches) { return rawurldecode("%" . $matches[1]); }, $val);
/* other escaped chars */
$from = ['\\\\', '\r', '\t', '\n', '\"', '\b', '\f', '\/'];
$to = ['\\', "\r", "\t", "\n", '"', "\b", "\f", '/'];
Expand Down Expand Up @@ -167,7 +164,6 @@ public function countTriples()
public function addT($s = '', $p = '', $o = '', $s_type = '', $o_type = '', $o_dt = '', $o_lang = '')
{
$o = $this->toUTF8($o);
// echo str_replace($this->base, '', "-----\n adding $s / $p / $o\n-----\n");
$t = ['s' => $s, 'p' => $p, 'o' => $o, 's_type' => $s_type, 'o_type' => $o_type, 'o_datatype' => $o_dt, 'o_lang' => $o_lang];
if ($this->skip_dupes) {
$h = md5(serialize($t));
Expand Down
40 changes: 18 additions & 22 deletions parsers/ARC2_RDFXMLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,12 @@ public function h1Open($t, $a)
if (isset($a[$this->rdf.'ID'])) {
$s['type'] = 'uri';
$s['value'] = $this->calcURI('#'.$a[$this->rdf.'ID'], $s['x_base']);
}
/* about */
elseif (isset($a[$this->rdf.'about'])) {
} elseif (isset($a[$this->rdf.'about'])) {
/* about */
$s['type'] = 'uri';
$s['value'] = $this->calcURI($a[$this->rdf.'about'], $s['x_base']);
}
/* bnode */
else {
} else {
/* bnode */
$s['type'] = 'bnode';
if (isset($a[$this->rdf.'nodeID'])) {
$s['value'] = '_:'.$a[$this->rdf.'nodeID'];
Expand All @@ -301,16 +299,14 @@ public function h1Open($t, $a)
$this->addT($sup_s['value'], $sup_s['p'], $coll['value'], $sup_s['type'], $coll['type']);
$this->addT($coll['value'], $this->rdf.'first', $s['value'], $coll['type'], $s['type']);
$this->pushS($coll);
}
/* new entry in existing coll */
elseif (isset($sup_s['is_coll']) && $sup_s['is_coll']) {
} elseif (isset($sup_s['is_coll']) && $sup_s['is_coll']) {
/* new entry in existing coll */
$coll = ['value' => $this->createBnodeID(), 'type' => 'bnode', 'is_coll' => true, 'x_base' => $s['x_base'], 'x_lang' => $s['x_lang']];
$this->addT($sup_s['value'], $this->rdf.'rest', $coll['value'], $sup_s['type'], $coll['type']);
$this->addT($coll['value'], $this->rdf.'first', $s['value'], $coll['type'], $s['type']);
$this->pushS($coll);
}
/* normal sub-node */
elseif (isset($sup_s['p']) && $sup_s['p']) {
} elseif (isset($sup_s['p']) && $sup_s['p']) {
/* normal sub-node */
$this->addT($sup_s['value'], $sup_s['p'], $s['value'], $sup_s['type'], $s['type']);
}
}
Expand All @@ -328,7 +324,10 @@ public function h1Open($t, $a)
}
/* any other attrs (skip rdf and xml, except rdf:_, rdf:value, rdf:Seq) */
foreach ($a as $k => $v) {
if (((!str_contains($k, $this->xml)) && (!str_contains($k, $this->rdf))) || preg_match('/(\_[0-9]+|value|Seq|Bag|Alt|Statement|Property|List)$/', $k)) {
if (
((!str_contains($k, $this->xml)) && (!str_contains($k, $this->rdf)))
|| preg_match('/(\_[0-9]+|value|Seq|Bag|Alt|Statement|Property|List)$/', $k)
) {
if (strpos($k, ':')) {
$this->addT($s['value'], $k, $v, $s['type'], 'literal', '', $s['x_lang']);
}
Expand Down Expand Up @@ -385,9 +384,8 @@ public function h2Open($t, $a)
unset($s['p_id']);
}
$this->state = 3;
}
/* named bnode */
elseif (isset($a[$this->rdf.'nodeID'])) {
} elseif (isset($a[$this->rdf.'nodeID'])) {
/* named bnode */
$o['value'] = '_:'.$a[$this->rdf.'nodeID'];
$o['type'] = 'bnode';
$this->addT($s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
Expand All @@ -396,9 +394,8 @@ public function h2Open($t, $a)
if (isset($s['p_id'])) {
$this->reify($this->calcURI('#'.$s['p_id'], $b), $s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
}
}
/* parseType */
elseif (isset($a[$this->rdf.'parseType'])) {
} elseif (isset($a[$this->rdf.'parseType'])) {
/* parseType */
if ('Literal' === $a[$this->rdf.'parseType']) {
$s['o_xml_level'] = 0;
$s['o_xml_data'] = '';
Expand All @@ -421,9 +418,8 @@ public function h2Open($t, $a)
$s['o_is_coll'] = true;
$this->state = 4;
}
}
/* sub-node or literal */
else {
} else {
/* sub-node or literal */
$s['o_cdata'] = '';
if (isset($a[$this->rdf.'datatype'])) {
$s['o_datatype'] = $a[$this->rdf.'datatype'];
Expand Down
5 changes: 2 additions & 3 deletions parsers/ARC2_SPARQLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,8 @@ public function xIRI_REF($v)
return [$r[1], $r[2]];
} elseif ($r = $this->x('\<([^\<\>\s\"\|\^`]*)\>', $v)) {
return [$r[1] ? $r[1] : true, $r[2]];
}
/* allow reserved chars in obvious IRIs */
elseif ($r = $this->x('\<(https?\:[^\s][^\<\>]*)\>', $v)) {
} elseif ($r = $this->x('\<(https?\:[^\s][^\<\>]*)\>', $v)) {
/* allow reserved chars in obvious IRIs */
return [$r[1] ? $r[1] : true, $r[2]];
}

Expand Down
11 changes: 4 additions & 7 deletions store/ARC2_RemoteStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public function runQuery($q, $qt = '', $infos = '')
$mappings = ['rdfxml' => 'RDFXML', 'sparqlxml' => 'SPARQLXMLResult', 'turtle' => 'Turtle'];
if (!$format || !isset($mappings[$format])) {
return $resp;
// return $this->addError('No parser available for "' . $format . '" SPARQL result');
}
/* format parser */
$suffix = $mappings[$format].'Parser';
Expand All @@ -173,15 +172,13 @@ public function runQuery($q, $qt = '', $infos = '')
} else {
$r = $bid;
}
}
/* select */
elseif (('select' == $qt) && !method_exists($parser, 'getRows')) {
} elseif (('select' == $qt) && !method_exists($parser, 'getRows')) {
/* select */
$r = $resp;
} elseif ('select' == $qt) {
$r = ['rows' => $parser->getRows(), 'variables' => $parser->getVariables()];
}
/* any other */
else {
} else {
/* any other */
$r = $parser->getSimpleIndex(0);
}
unset($parser);
Expand Down
5 changes: 2 additions & 3 deletions store/ARC2_Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,8 @@ public function getTermID($val, $term = '')
}
}
}
}
/* exact match */
else {
} else {
/* exact match */
$sql = 'SELECT id
FROM '.$this->getTablePrefix().$tbl."
WHERE val = BINARY '".$this->db->escape($val)."'
Expand Down
10 changes: 4 additions & 6 deletions store/ARC2_StoreDeleteQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ public function runQuery($infos)
/* graph(s) only */
if (!$this->v('construct_triples', [], $this->infos['query'])) {
$tc = $this->deleteTargetGraphs();
}
/* graph(s) + explicit triples */
elseif (!$this->v('pattern', [], $this->infos['query'])) {
} elseif (!$this->v('pattern', [], $this->infos['query'])) {
/* graph(s) + explicit triples */
$tc = $this->deleteTriples();
}
/* graph(s) + constructed triples */
else {
} else {
/* graph(s) + constructed triples */
$tc = $this->deleteConstructedGraph();
}
$t2 = ARC2::mtime();
Expand Down
3 changes: 2 additions & 1 deletion store/ARC2_StoreLoadQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ public function getStoredTermID($val, $type_id, $tbl)
$tbl_prefix = $this->store->getTablePrefix();
$sub_tbls = ('id' == $tbl)
? ['id2val', 's2val', 'o2val']
: ('s' == $tbl
: (
's' == $tbl
? ['s2val', 'id2val', 'o2val']
: ['o2val', 'id2val', 's2val']
);
Expand Down
19 changes: 10 additions & 9 deletions store/ARC2_StoreSelectQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ public function getGraphInfos($id)
}

return array_merge($this->getGraphInfos($pattern['parent_id']), $r);
}
/* FROM / FROM NAMED */
else {
} else {
/* FROM / FROM NAMED */
if (isset($this->infos['query']['dataset'])) {
foreach ($this->infos['query']['dataset'] as $set) {
$r[] = array_merge(['type' => 'dataset'], $set);
Expand Down Expand Up @@ -548,14 +547,16 @@ public function getQuerySQL()
return ''.(
$this->is_union_query
? 'SELECT'
: 'SELECT'.$this->getDistinctSQL()).$nl.
: 'SELECT'.$this->getDistinctSQL()
).$nl.
$this->getResultVarsSQL().$nl. /* fills $index['sub_joins'] */
$this->getFROMSQL().
$this->getAllJoinsSQL().
$this->getWHERESQL().
$this->getGROUPSQL().
$this->getORDERSQL().
($this->is_union_query
(
$this->is_union_query
? ''
: $this->getLIMITSQL()
).$nl.'';
Expand Down Expand Up @@ -608,9 +609,8 @@ public function getResultVarsSQL()
$r .= $var['aggregate'].'('.$conv_code.$distinct_code.$tbl_alias.') AS `'.$var['alias'].'`';
$added[$var['alias']] = 1;
}
}
/* normal var */
else {
} else {
/* normal var */
if (!isset($added[$var_name])) {
$r .= $r ? ','.$nl.' ' : ' ';
$r .= $tbl_alias.' AS `'.$var_name.'`';
Expand Down Expand Up @@ -1216,7 +1216,8 @@ public function getFilterPatternSQL($pattern, $context)
/* some really ugly tweaks */
/* empty language filter: FILTER ( lang(?v) = '' ) */
$r = preg_replace(
'/\(\/\* language call \*\/ ([^\s]+) = ""\)/s', '((\\1 = "") OR (\\1 LIKE "%:%"))',
'/\(\/\* language call \*\/ ([^\s]+) = ""\)/s',
'((\\1 = "") OR (\\1 LIKE "%:%"))',
$r
);

Expand Down

0 comments on commit 45bd0d1

Please sign in to comment.