Conversation
a1fa945 to
6a0ca80
Compare
30f20fc to
7d9faf7
Compare
7d9faf7 to
3cca01b
Compare
a98ede3 to
18afec6
Compare
c912d90 to
2c80ef9
Compare
2c80ef9 to
edac916
Compare
ba3d8fe to
143e27b
Compare
b76f569 to
2adc875
Compare
| $a[$rdf] = $parser->getSimpleIndex(0); | ||
| } elseif ( | ||
| is_array($a[$rdf]) | ||
| and isset($a[$rdf][0]) |
There was a problem hiding this comment.
I'd long since forgotten and existed in PHP...!
| * @param ObjectType $type | ||
| */ | ||
| private function get_subjects_where($p, $o, $type) | ||
| private function get_subjects_where(string $p, $o, string $type): array |
There was a problem hiding this comment.
Why does the docblock type it as a TriplePredicate but in the function it types it as a string ?
There was a problem hiding this comment.
Types like TriplePredicate, ObjectValue are PHPStan type aliases, defined here:
tripod-php/src/classes/ExtendedGraph.php
Lines 12 to 17 in 2adc875
(though language servers in PHPStorm, Intelephense in VSCode, etc. also interpret them and provide completions based on them)
I'm using TriplePredicate for consistency, even though it translates to just string. This helps make a better sense of what's inside the object, which is especially visible here:
tripod-php/src/classes/ExtendedGraph.php
Line 19 in 2adc875
I think this enhances the reading experience as you can quickly find where predicates are referenced, such as here:
tripod-php/src/classes/ExtendedGraph.php
Lines 954 to 956 in 2adc875
So you know it's not just an array being returned, it's an array of predicates.
| * @param 'literal'|'resource' $type | ||
| */ | ||
| private function add_to_sequence($s, $o, $type = 'resource') | ||
| private function add_to_sequence(string $s, $o, string $type = 'resource'): void |
There was a problem hiding this comment.
Same question as above, but TripleSubject vs. string
| @@ -0,0 +1,17 @@ | |||
| parameters: | |||
| level: 5 | |||
astilla
left a comment
There was a problem hiding this comment.
Well...it's massive... 🤣
Looks like some good automated updates.
I've left a couple of questions I wasn't sure about a difference in typing between docblock and function param definition.
Other than than it looks sane but being so big I've somewhat skimmed it.
mike-dean-talis
left a comment
There was a problem hiding this comment.
I reached the end. Holy moly. That's 2 hours I won't get back.
This generally looks good to me although I have a few questions and observations along the way.
|
|
||
| if (empty($options) || isset($options['h']) || isset($options['help']) | ||
| if ( | ||
| $options === [] || $options === false || isset($options['h']) || isset($options['help']) |
There was a problem hiding this comment.
comment: I am surprised that $options === [] works as intended to be honest. empty does check for false-y values, so I am surprised this is necessary.
There was a problem hiding this comment.
This is on Rector: https://getrector.com/rule-detail/disallowed-empty-rule-fixer-rector.
Since PHP's getopt can return array|false that's what's it checking for.
From type safety standpoint this make more sense, since the definition of what "empty" means in PHP is quite loose...
$ php -r 'var_dump(empty("0"));'
bool(true)| } else { | ||
| $id = null; | ||
| } | ||
| $id = isset($options['i']) || isset($options['id']) ? $options['i'] ?? $options['id'] : null; |
There was a problem hiding this comment.
comment: I wonder if we can make it simpler than this:
$id = $options['i'] ?? $options['id'] ?? null; We seem to do similar elsewhere, so I won't go through them all (I'll be here forever) but you can get my point.
There was a problem hiding this comment.
True, I missed this. Automagic tools can only take us so far I guess...
| Config::getInstance()->setMongoCursorTimeout(-1); | ||
|
|
||
| echo "Generating {$tableId}"; | ||
| echo 'Generating ' . $tableId; |
There was a problem hiding this comment.
question: I am not entirely sure what was "bad" about the previous syntax? We do a lot of interleaved strings like this in JS, I just wonder what makes it "modern" to go backwards? Anyway... enough of my opinionated waffle.
There was a problem hiding this comment.
Again, Rector at play: https://getrector.com/rule-detail/encapsed-strings-to-sprintf-rector
I believe it's about consistency:
-
In PHP, unlike JS,
{}is limited, and only works with variables:echo "{$var}"; echo "{$obj->prop}"; echo "{$obj->method()}"; echo "{$obj::$staticProp}"; echo "{$obj::static()}"; # But you can't e.g.: echo "{func()}"; echo "{CONSTANT}"; echo "{SomeClass::static()}";
-
There is also cursed, deprecated,
"${var}"syntax.
| $json = json_encode(['namespaces' => $config['namespaces']]); | ||
|
|
||
| echo indent($json); | ||
| echo json_encode(['namespaces' => $config['namespaces']], JSON_PRETTY_PRINT); |
There was a problem hiding this comment.
praise: This one made me laugh out loud. Why have 50 lines when you can have one? 👍
scripts/mongo/loadTriples.php
Outdated
| $subject = trim($parts[0], '><'); | ||
|
|
||
| if (empty($currentSubject)) { // set for first iteration | ||
| if ($currentSubject === '' || $currentSubject === '0') { // set for first iteration |
There was a problem hiding this comment.
comment: This PR makes me wonder if there is something inherently wrong with empty? As it seems to be avoided in favour of direct comparisons that I wouldn't usually use.
There was a problem hiding this comment.
See my comment above; but yes, Rector seem to prefer to avoid empty since it's a catch-all for null, false, '', '0', 0, 0.0, []. Converting to an explicit comparison forces you to think about types and possible values.
That said: 119a88f
| if ( | ||
| preg_match('~^[a-zA-Z][a-zA-Z0-9\-]+$~', $parts[$i]) | ||
| && !isset($this->_ns[$parts[$i]]) | ||
| && $parts[$i] != 'schema' | ||
| && $parts[$i] != 'ontology' | ||
| && $parts[$i] != 'vocab' | ||
| && $parts[$i] != 'terms' | ||
| && $parts[$i] != 'ns' | ||
| && $parts[$i] != 'core' | ||
| && strlen($parts[$i]) > 3 | ||
| ) { |
There was a problem hiding this comment.
comment: This is my favourite if statement. I have no idea what it's really doing or why.
No change necessary just... man. I despair.
There was a problem hiding this comment.
We'll never know. It dates back to the Initial commit
https://github.com/talis/tripod-php/blame/428acd7e190e2427a8ee8dce724afc79b0ea249f/src/classes/Labeller.class.php#L345
| * @param array $index | ||
| */ | ||
| public function getSerializedIndex($index, $context) | ||
| public function getSerializedIndex($index, ?string $context): string |
There was a problem hiding this comment.
question: Can we not type $index as an array? Maybe I have missed something obvious.
There was a problem hiding this comment.
It's not you, it'm me (and Rector) who missed this.
Yes, we can type it: 4a8479e
| $milliseconds = (int) $lastUpdatedDate->__toString(); | ||
| $seconds = intdiv($milliseconds, 1000); | ||
| $fraction = ($milliseconds % 1000) / 1000; | ||
|
|
||
| return sprintf('%.8f %d', $fraction, $seconds); |
There was a problem hiding this comment.
praise: I think this is doing the same work. I'm hoping tests would catch it if not. This makes the process more readable at least.
There was a problem hiding this comment.
Though why microtime format was chosen in the first place evades me...
| $this->assertInstanceOf(Tripod\Mongo\Config::class, $instance); | ||
| $this->assertInstanceOf(ITripodConfigSerializer::class, $instance); | ||
| $this->assertEquals( | ||
| $this->assertSame( |
There was a problem hiding this comment.
praise: Bless your soul. assertSame.
| public function mandatoryArgDataProvider(): iterable | ||
| { | ||
| return [ | ||
| ['tripodConfig', 'tripodConfig or tripodConfigGenerator'], | ||
| ['storeName'], | ||
| ['reindex'], | ||
| ['background'], | ||
| ]; | ||
| yield ['tripodConfig', 'tripodConfig or tripodConfigGenerator']; | ||
| yield ['storeName']; | ||
| yield ['reindex']; | ||
| yield ['background']; |
There was a problem hiding this comment.
praise: Another thing I didn't know PHP had... iterators. Well, I hope to add that one to my repertoire.
There was a problem hiding this comment.
Generators are pretty neat.
But for writing tests with many cases wait for PHP attributes!
https://github.com/talis/depot/blob/b2d73c12/server/tests/unit/VaultTest.php#L19-L25
todo: use ObjectId->getTimestamp()Used
rector.php