azuyalabs / yasumi

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

create $year should by typed #75

Closed huehnerhose closed 5 years ago

huehnerhose commented 7 years ago

I ran into the problem, that I call create (or createByISO3166_2 in my case) like this:

$holidays = Yasumi\Yasumi::createByISO3166_2(
            $region,
            $date->format("Y"),
            "de_DE"
        );

Since $date->format("Y") gives me a string the later comparisons inside Yasumi failed

if ($year === 2017)

I see three ways solvings this: 1) TypeHinting. My prefered solution 2) Casting / Validating inside the create function (that what type hinting is for) 3) changing the === to type unaware == (Not a solution at all :) )

I saw the documentation states integer as $year but I imagine this to be a stupid trap you can walk into unaware and php offers a nice solution for it.

stelgenhof commented 7 years ago

Thank you for catching this. Looking at the three possibilities, I am also in favor of type hinting.

stelgenhof commented 5 years ago

Yasumi v2 has been released. This has been resolved now.