mirror of
https://github.com/rlanvin/php-rrule.git
synced 2024-11-28 05:24:10 +01:00
Fix insufficient type detection for FREQ and WKST
In some cases non-string types would end up passed to strtoupper which causes a deprecation warning from PHP 8.3. There might be other places where stricter type check is needed Ref #149
This commit is contained in:
parent
4b19d8ef60
commit
a2dd785693
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
|
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
|
||||||
name: PHP ${{ matrix.php }}
|
name: PHP ${{ matrix.php }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
@ -219,34 +219,38 @@ class RRule implements RRuleInterface
|
|||||||
$this->rule = $parts; // save original rule
|
$this->rule = $parts; // save original rule
|
||||||
|
|
||||||
// WKST
|
// WKST
|
||||||
$parts['WKST'] = strtoupper($parts['WKST']);
|
if (is_string($parts['WKST'])) {
|
||||||
if (! array_key_exists($parts['WKST'], self::WEEKDAYS)) {
|
$parts['WKST'] = strtoupper($parts['WKST']);
|
||||||
|
if (array_key_exists($parts['WKST'], self::WEEKDAYS)) {
|
||||||
|
$this->wkst = self::WEEKDAYS[$parts['WKST']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->wkst) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
'The WKST rule part must be one of the following: '
|
'The WKST rule part must be one of the following: '
|
||||||
.implode(', ',array_keys(self::WEEKDAYS))
|
.implode(', ',array_keys(self::WEEKDAYS))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->wkst = self::WEEKDAYS[$parts['WKST']];
|
|
||||||
|
|
||||||
// FREQ
|
// FREQ
|
||||||
if (is_integer($parts['FREQ'])) {
|
if (is_integer($parts['FREQ'])) {
|
||||||
if ($parts['FREQ'] > self::SECONDLY || $parts['FREQ'] < self::YEARLY) {
|
if ($parts['FREQ'] <= self::SECONDLY && $parts['FREQ'] >= self::YEARLY) {
|
||||||
throw new \InvalidArgumentException(
|
$this->freq = $parts['FREQ'];
|
||||||
'The FREQ rule part must be one of the following: '
|
|
||||||
.implode(', ',array_keys(self::FREQUENCIES))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$this->freq = $parts['FREQ'];
|
|
||||||
}
|
}
|
||||||
else { // string
|
elseif (is_string($parts['FREQ'])) {
|
||||||
$parts['FREQ'] = strtoupper($parts['FREQ']);
|
$parts['FREQ'] = strtoupper($parts['FREQ']);
|
||||||
if (! array_key_exists($parts['FREQ'], self::FREQUENCIES)) {
|
if (array_key_exists($parts['FREQ'], self::FREQUENCIES)) {
|
||||||
throw new \InvalidArgumentException(
|
$this->freq = self::FREQUENCIES[$parts['FREQ']];
|
||||||
'The FREQ rule part must be one of the following: '
|
|
||||||
.implode(', ',array_keys(self::FREQUENCIES))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$this->freq = self::FREQUENCIES[$parts['FREQ']];
|
}
|
||||||
|
|
||||||
|
if (!$this->freq) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'The FREQ rule part must be one of the following: '
|
||||||
|
.implode(', ',array_keys(self::FREQUENCIES))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// INTERVAL
|
// INTERVAL
|
||||||
|
@ -20,8 +20,12 @@ class RRuleTest extends TestCase
|
|||||||
array(array()),
|
array(array()),
|
||||||
array(array('FOOBAR' => 'DAILY')),
|
array(array('FOOBAR' => 'DAILY')),
|
||||||
|
|
||||||
array(array('FREQ' => 'foobar')),
|
'invalid string freq' => [['FREQ' => 'foobar']],
|
||||||
'Invalid integer frequency' => [['FREQ' => 42]],
|
'Invalid integer frequency' => [['FREQ' => 42]],
|
||||||
|
'Array freq' => [['FREQ' => array()]],
|
||||||
|
'null freq' => [['FREQ' => null]],
|
||||||
|
'object freq' => [['FREQ' => new Stdclass()]],
|
||||||
|
|
||||||
array(array('FREQ' => 'DAILY', 'INTERVAL' => -1)),
|
array(array('FREQ' => 'DAILY', 'INTERVAL' => -1)),
|
||||||
array(array('FREQ' => 'DAILY', 'INTERVAL' => 1.5)),
|
array(array('FREQ' => 'DAILY', 'INTERVAL' => 1.5)),
|
||||||
array(array('FREQ' => 'DAILY', 'UNTIL' => 'foobar')),
|
array(array('FREQ' => 'DAILY', 'UNTIL' => 'foobar')),
|
||||||
@ -87,6 +91,9 @@ class RRuleTest extends TestCase
|
|||||||
array(array('FREQ' => 'MONTHLY', 'BYSECOND' => 61)),
|
array(array('FREQ' => 'MONTHLY', 'BYSECOND' => 61)),
|
||||||
|
|
||||||
'Invalid WKST' => [['FREQ' => 'DAILY', 'WKST' => 'XX']],
|
'Invalid WKST' => [['FREQ' => 'DAILY', 'WKST' => 'XX']],
|
||||||
|
'Null WKST' => [['FREQ' => 'DAILY', 'WKST' => null]],
|
||||||
|
'Array WKST' => [['FREQ' => 'DAILY', 'WKST' => array()]],
|
||||||
|
'Object WKST' => [['FREQ' => 'DAILY', 'WKST' => new stdClass()]],
|
||||||
|
|
||||||
'Invalid DTSTART (invalid date)' => [['FREQ' => 'DAILY', 'DTSTART' => new stdClass()]]
|
'Invalid DTSTART (invalid date)' => [['FREQ' => 'DAILY', 'DTSTART' => new stdClass()]]
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user