Tags: dereuromark/cakephp-shim
Tags
Apply conservative Rector cleanup (#129) * Apply conservative Rector cleanup * Run PHPCS cleanup * Restore test setup and typed property guards * Reformat folder fixture setup * Restore readable compact formatting * Fix cleanup branch regressions * Fix cleanup branch regressions
Shim polish: drop misleading deprecation tags, harden defensive paths… …, modernize PHP 8 idioms (#125) A handful of small correctness / hygiene fixes left over from the previous correctness PR: - RequestHandlerComponent::accepts() / prefers() carried `deprecated 4.4.0` doc tags copied verbatim from the upstream core they were extracted from. The whole purpose of this shim is to re-introduce that surface for consumers who have not yet migrated to ContentTypeNegotiation / Controller::getViewClasses(), so flagging them deprecated *inside the shim* is misleading. Drop the tags. - DateTimeWidget meridian conversion read the AM/PM character from $dateArray (the post-padded copy) but the conditional checked $value (the raw input). The decoupling between the conditional source and the value source was brittle and has been a historical bug source. Use $value['meridian'] for both. - Table::record() caught RecordNotFoundException with an empty `catch (X \$e)` body, which PSR2R / phpcs flags. Switch to PHP 8 capture-omit `catch (RecordNotFoundException) { return null; }`. - Table::delete() weakened the parent's typed `array \$options` to bare `\$options` and then re-checked is_array() at runtime — under declare(strict_types=1) the runtime check is dead because callers already type-hint array. Restore the parent's `array \$options` hint and drop the dead check. - LegacyModelAwareTrait::loadModel() read `\$this->_modelFactories` unconditionally. That property only existed on ModelAwareTrait in 4.x; the trait was removed in 5.x, so consumers that don't redeclare the property hit an undeclared-dynamic-property warning under PHP 8.2+. Guard with property_exists() so the lookup falls back to FactoryLocator cleanly. - Folder::isAbsolute() / isWindowsPath() / isRegisteredStreamWrapper() were returning int|false from preg_match() directly into a `: bool` signature, papered over by `||` short-circuiting. Cast (bool) explicitly. Also swap `substr(\$path, 0, 2) === '\\\\\\\\'` for str_starts_with() (PHP 8.0+). - Deprecations.php: add declare(strict_types=1) to match the rest of src/, and validate the `Shim.deprecationType` value before passing it to trigger_error() — only E_USER_NOTICE / WARNING / DEPRECATED / ERROR are accepted by trigger_error, and a misconfigured app passing e.g. E_NOTICE would crash the shim's own deprecation pathway with a ValueError on PHP 8+. - TestSuite\\TestTrait: drop the `&` reference on the \$object parameter of invokeMethod() and invokeProperty(). Objects are passed by handle in PHP, the reference does nothing. EntityAnnotatorTest overrode invokeMethod() with the same signature and is updated to match.
Fix SetTrait magic setOrFail off-by-one in argument index (#123) The magic set{PropertyName}OrFail($value) helpers in SetTrait::__call and GetSetTrait::__call read the first user argument from $arguments[1] instead of $arguments[0]. With the documented one-arg signature this raises an "Undefined array key 1" notice and then forwards null to setOrFail(), which throws "$prop is null" — so $entity->setFooBarOrFail('value') always fails on the success path. The bug was masked by EntitySetTest::testSetOrFailMagicInvalid, which called setFooBarOrFail('foo_bar', null) with two args; the second null happened to match the bug and made the exception assertion succeed. Read $arguments[0] in both traits, switch the invalid-path test to the documented single-arg signature, and add a positive-path magic-set test plus a missing-argument regression test.
PreviousNext