azuyalabs / yasumi

The easy PHP Library for calculating holidays
https://www.yasumi.dev
Other
1.04k stars 152 forks source link

RFC: Using class constants for holiday names #198

Closed ravage84 closed 4 years ago

ravage84 commented 4 years ago

This is a Request For Comment.

To be honest, I just came across your fine library,haven't had a chance to use it yet. But while I was browsing through the documentation and code, I was wondering why the names of the holidays are (magic) literals instead of class constants.

So ,for example, instead of doing this:

        $this->removeHoliday('christmasDay');
        $this->removeHoliday('secondChristmasDay');
        $this->removeHoliday('someOtherSwissNationalHoliday');

It could be this:

        $this->removeHoliday(Holidays::CHRISTMAS_DAY);
        $this->removeHoliday(Holidays::SECOND_CHRISTMAS_DAY);
        $this->removeHoliday(SwissHolidays::SOME_OTHER_HOLIDAY);

Magic literals can become a maintenance problem. Having class contants for them would centralize those magic literals, contain them & would make it possible to document them (with doc blocks, for example). Also having them would improve the developer experience as it would make them searchable through the IDEs.

stelgenhof commented 4 years ago

As for the why, there isn't a particular reason and definitely agree that class constants should be used instead. It might take a bit of time before all literals are transposed to class constants.

Cheers! Sacha

github-actions[bot] commented 4 years ago

This issue has been open 30 days with no activity. Please remove the stale label or comment, or this will be closed in 5 days