Commit graph

14 commits

Author SHA1 Message Date
thiemowmde 8f81812242 Enable and enforce a few extra PHPCS sniffs
This is not really anything new. Most code already followed these
sniffs. This patch just fixes the remaining exceptions. Also:
* Remove PHPDoc blocks that don't add anything but just repeat the
  strict types.
* Remove @file comments in favor of class-level comments.
* Add strict types where possible, most notably some `void`.

Change-Id: Iff6872dff68170b0fc4e82ac2ba3cad385e8773e
2023-09-06 18:15:22 +02:00
thiemowmde bb7b801b64 Show much more actionable context when paramOrder is incomplete
So far we show nothing but the index in the "paramOrder" array. This
is especially useless when a parameter is missing. The index just
points to the end of the array then.

Same when an unknown parameter appears. What the user needs is not
the index but the name of the unknown parameter.

I played around with a few formats. As suggested in this patch:
 Required property "paramOrder[ "foo" ]" not found.
 Invalid value for property "paramOrder[ "foo" ]".

A possible alternative is:
 Required property "paramOrder[0] ("foo")" not found.
 Invalid value for property "paramOrder[0] ("foo")".

Bug: T340377
Change-Id: I1dbef1b6e585d5b972a0c9a373a040aee6027cf3
2023-08-21 12:52:42 +02:00
Thiemo Kreuz 647cd0bc65 Clean up base class reaching into the subclass
This does not change anything. It's only about the readabilility
of the code.

Change-Id: Ia908bd90ebc261f3bebc7854501a6f5d5e736384
2023-06-09 07:10:19 +00:00
thiemowmde b632162245 Add missing validation for empty parameter names
Note this will make the templatedata API temporarily fail for
templates that are affected by this, until their documentation is
fixed. I think we have two ways to proceed here:

1. Thanks to Ie572809 we can change the API module to not do the
validation again. This allows us to make the validation more strict,
but the API module will continue to deliver the same data as before
until the parser cache is invalidated.

2. We accept it and merge this patch as it is. The problem is
extremely rare and easy to fix.

Bug: T333826
Change-Id: I16c7cc2328c47dde196e2dc07edb2eace33a624f
2023-04-11 19:08:37 +00:00
Thiemo Kreuz 7a32cba3ef Split validation and normalization into separate services
This makes it possible to use these steps independent from each
other. For example, a future patch can get rid of the re-validation
that's done over and over again when the API is called.

A significant change is that this gets rid of an expensive deep
clone. It was necessary before exactly because validation and
normalization was intertwined. Normalized properties would mess with
the later inheritance.

Strictly splitting validation and normalization (and executing them
in this order) solved this. The only downside of this is that
inherited properties are validated twice. But this is much less of a
problem, compared to the deep clone, I would like to argue.

This was always covered by tests. You can still see the tests fail
when you flip the execution order of inheritance and parameter
validation.

Bug: T301337
Change-Id: Ie5728094f9ed813f53b709d8b5283c4b99dc7d63
2023-03-06 13:05:51 +00:00
Thiemo Kreuz 505a835c49 Extract named isValidCustomFormatString() method
Bug: T301337
Change-Id: I02e81c264e7ebeb60483d7eacf9fa7b27ad1e545
2022-12-15 12:15:35 +00:00
jenkins-bot e1b5970d3f Merge "Split parameter validation off as separate methods" 2022-12-13 21:09:37 +00:00
libraryupgrader ca32a8ced1 build: Updating mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: If6ebb246effabc99b7d72a336bacee65c54b5c67
2022-10-09 15:42:03 +00:00
Thiemo Kreuz c0755ea392 Split parameter validation off as separate methods
This only moves code around but doesn't change anything. The tests
should prove this. The only change is that validating if "inherits"
points to an existing parameter is now done a little earlier as part
of validateParameters().

Bug: T301337
Change-Id: I20865d8f93ea0f3cb1c0683804c7871056a700a8
2022-07-15 11:11:32 +02:00
Thiemo Kreuz 8fec04c8fd Remove unreachable validation step
I tried to write a test that can cover this code, but realized it is
unreachable. All parameters with all their properties are already
validated in the first loop.

Bug: T301337
Change-Id: If97adba45beb0ef1303907746715613fca23468e
2022-02-22 10:51:00 +01:00
Thiemo Kreuz 78e6239444 Split validation into some smaller steps
Bug: T260980
Change-Id: Ibc88b5fd8f8ece919032d13320cad74d9be74bfc
2022-02-02 12:18:34 +00:00
Thiemo Kreuz dc82db422b Use more specific instanceof stdClass instead of is_object()
PHP is a little weird in so far that what you get from e.g. `(object)[]`
or json_decode() are not objects but stdClass instances. You can think
of stdClass as a subclass of object, i.e. it's more specific.

Using is_object() means that stuff like ArrayIterator will be accepted,
which is not correct in this context here.

Change-Id: I0bffc54508ac7a27bbb59c3aabb9695158eb96b3
2022-02-02 11:45:59 +00:00
Thiemo Kreuz 15aa40aa1d Rename all $paramObj to $param
The word "param" is not really that ambiguous in this context. The
only other meaning it could have is "parameter name". Such places
already use $paramName.

This makes the following patches easier to review.

Change-Id: I1e6210d1ca7d58726a0fc3b3396d75e0e28c16d8
2022-02-01 15:47:53 +01:00
Thiemo Kreuz 8c24751491 Split validation and HTML formatting into separate services
No functional change was made to the code. It was only moved from one
place to another. Note there are a lot of tests that cover this code.
The tests haven't been touched on purpose. Splitting these as well
is something for a later patch.

Bug: T260980
Change-Id: I9fa0fa87768f2560b83a1b5f3d39211ea9d6cfad
2022-02-01 15:47:52 +01:00