cron-expression icon indicating copy to clipboard operation
cron-expression copied to clipboard

[Bugfix] Return static from factory

Open simPod opened this issue 7 years ago • 5 comments

simPod avatar May 09 '18 16:05 simPod

@dragonmantank any chance you could find a time and review this? Thanks!

simPod avatar Aug 05 '18 13:08 simPod

Hello, thanks for the PR.

What exactly is the reason for the change? While technically static doesn't cause confusion in things like PHPStorm, it does make it less clear what the factory returns.

dragonmantank avatar Aug 06 '18 01:08 dragonmantank

The return type Cron\CronExpression is incorrect. As the class is not final, it is extensible. Therefore, when you extend it

final class MyOwnCronExpression extends \Cron\CronExpression

All static checks in IDE or other static analysis tool fail for

public function someOtherFcn(MyOwnCronExpression $myOwnCronExpression) {
...
}


someOtherFcn($myOwnCronExpression); // this thinks you are passing `\Cron\CronExpression` even though you're passing MyOwnCronExpression
// because it was created using `factory()` with incorrect typehint.

The proper definition would be

     * @return CronExpression
     */
    public static function factory($expression, FieldFactory $fieldFactory = null) : self

but php 7.0 is still supported here so it is not possible.

simPod avatar Aug 06 '18 09:08 simPod

Hi @dragonmantank, the phpdocs are still incorrect. Can this be merged, please?

simPod avatar Jan 23 '19 15:01 simPod

@dragonmantank :(

it does make it less clear what the factory returns.

That's just false, it makes it precisely clear what it returns.

simPod avatar Mar 24 '19 23:03 simPod