-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix typos in comments, add phpdocs, replace NBSP by space, simplify phpunit #1142
Conversation
Kudos, SonarCloud Quality Gate passed!
|
@@ -6,7 +6,6 @@ class WDQSResource extends RemoteResource | |||
const WDQS_ENDPOINT = "https://query.wikidata.org/sparql"; | |||
|
|||
public function resolve(int $timeout) : ?EasyRdf\Resource { | |||
$client = new EasyRdf\Sparql\Client(self::WDQS_ENDPOINT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-declared in the code below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Now that I look at it, it is a bit questionable why lines
Skosmos/model/resolver/WDQSResource.php
Lines 10 to 44 in 4774577
// unregister the legacy "json" format as it causes problems with CONSTRUCT requests | |
EasyRdf\Format::unregister('json'); | |
// change the timeout setting for external requests | |
$httpclient = EasyRdf\Http::getDefaultHttpClient(); | |
$httpclient->setConfig(array('timeout' => $timeout)); | |
$httpclient->setHeaders('Accept', 'text/turtle'); | |
EasyRdf\Http::setDefaultHttpClient($httpclient); | |
$uri = $this->uri; | |
$query = <<<EOQ | |
PREFIX wd: <http://www.wikidata.org/entity/> | |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | |
PREFIX schema: <http://schema.org/> | |
CONSTRUCT { | |
<$uri> rdfs:label ?label . | |
?link schema:about <$uri> ; | |
a ?linktype ; | |
schema:isPartOf ?whole ; | |
schema:inLanguage ?lang . | |
} | |
WHERE | |
{ | |
{ <$uri> rdfs:label ?label } | |
UNION | |
{ | |
?link schema:about <$uri> ; | |
a ?linktype ; | |
schema:isPartOf ?whole ; | |
schema:inLanguage ?lang . | |
} | |
} | |
EOQ; | |
$client = new EasyRdf\Sparql\Client(self::WDQS_ENDPOINT); |
try
block, though. I would expect them to succeed in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good point. We can move it out maybe in another PR? One thing that really bothers me in the code is the use of return $this->showError…
functions, while these showError
-etc functions actually do not return anything; but instead set HTTP header()
values, print to the stdout with echo()
and need the stream to be closed (with return
or exit
) somewhere.
e.g.
Skosmos/controller/RestController.php
Line 49 in c84dc97
return $this->returnError(400, "Bad Request", "Invalid limit parameter"); Skosmos/controller/Controller.php
Lines 179 to 184 in c84dc97
protected function returnError($code, $status, $message) { header("HTTP/1.0 $code $status"); header("Content-type: text/plain; charset=utf-8"); echo "$code $status : $message"; }
I started fixing that in this PR, but the change was getting quite big and I would need to do some manual testing to confirm it didn't break anything 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, best to leave it to another PR, this one is rock solid as it is! 😃
Heh, now that you pointed at it, it surely looks ugly. I also remember having some trouble with those things whilst trying to silence the extra output PHPUnit was printing whilst executing tests.
+1 for another PR.
Codecov Report
@@ Coverage Diff @@
## master #1142 +/- ##
============================================
- Coverage 67.96% 67.96% -0.01%
Complexity 1584 1584
============================================
Files 32 32
Lines 3890 3889 -1
============================================
- Hits 2644 2643 -1
Misses 1246 1246
Continue to review full report at Codecov.
|
* @param string $lang the language for displaying dates in the change list | ||
*/ | ||
* Formats the list of concepts as labels arranged by modification month | ||
* @param Array $changeList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like there are PHP types stated in both uppercase and lowercase (starting with) in PHPDocs all over the code base (array, for instance, here).
Well, I guess they do not matter. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that too. I think in this case I opened another code in this function, that returned Array
, and then I just typed Array
too 😄 but normally I use string
, boolean
, array
… happy to change it to lower case if preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is OK at this point.
We should anyways add type hints/declarations directly into function arguments and return values as requested in #727 but that can be done en masse, simultaneously double checking these PHPDocs.
@@ -1051,7 +1051,7 @@ public function testListConceptGroups() | |||
$voc = $this->model->getVocabulary('groups'); | |||
$graph = $voc->getGraph(); | |||
$sparql = new GenericSparql('http://localhost:13030/skosmos-test/sparql', $graph, $this->model); | |||
$actual = $sparql->ListConceptGroups('http://www.w3.org/2004/02/skos/core#Collection', 'en', false); | |||
$actual = $sparql->ListConceptGroups('http://www.w3.org/2004/02/skos/core#Collection', 'en'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good fix!
Oh my, PHP truly is case-insensitive. Hurts my eyes! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very solid improvements in this PR, thanks @kinow !
I am more than happy to merge this as-is.
Thanks for the review and helpful comments @kouralex ! |
I merged this now that I saw your last replies. 🎉 |
Happy to drop some commits if necessary 👍 Just syncing my local fork branch and taking a quick look at the current code base.