Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some deprecation warnings #64

Merged
merged 11 commits into from
Jan 29, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/dist
/tags
*.mo
.phpunit.result.cache

# IDE and editor specific files #
#################################
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: bash up down

up:
docker-compose up -d

down:
docker-compose down -v

bash:
docker-compose exec web bash
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ It means that composer will look at `master` branch of repository configured und

## Changelog

### 2024-01-19

- `strotime()` and `preg_split()` in CakeResponse deprecation warning fixes (passing null)

### 2024-01-11

- `preg_replace` deprecation warning fixes (passing null instead of `string`)
Expand Down
8 changes: 6 additions & 2 deletions lib/Cake/Network/CakeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -1164,15 +1164,19 @@ public function checkNotModified(CakeRequest $request) {
$ifNoneMatchHeader = $request->header('If-None-Match');
$etags = array();
if (is_string($ifNoneMatchHeader)) {
$etags = preg_split('/\s*,\s*/', $ifNoneMatchHeader, null, PREG_SPLIT_NO_EMPTY);
$etags = preg_split('/\s*,\s*/', $ifNoneMatchHeader, 0, PREG_SPLIT_NO_EMPTY);
}
$modifiedSince = $request->header('If-Modified-Since');
$checks = array();
if ($responseTag = $this->etag()) {
$checks[] = in_array('*', $etags) || in_array($responseTag, $etags);
}
if ($modifiedSince) {
$checks[] = strtotime($this->modified()) === strtotime($modifiedSince);
if ($this->modified() === null) {
$checks[] = strtotime($modifiedSince) === false;
} else {
$checks[] = strtotime($this->modified()) === strtotime($modifiedSince);
}
}
if (empty($checks)) {
return false;
Expand Down
16 changes: 12 additions & 4 deletions lib/Cake/Test/Case/Utility/CakeTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ public function testTimeAgoInWordsWithFormat() {
$this->assertEquals('on 2007-09-25', $result);

$result = $this->Time->timeAgoInWords('2007-9-25', '%x');
$this->assertEquals('on ' . strftime('%x', strtotime('2007-9-25')), $result);
// @codingStandardsIgnoreStart
$this->assertEquals('on ' . @strftime('%x', strtotime('2007-9-25')), $result);
// @codingStandardsIgnoreEnd

$result = $this->Time->timeAgoInWords(
strtotime('+2 weeks +2 days'),
Expand All @@ -303,7 +305,9 @@ public function testTimeAgoInWordsWithFormat() {
strtotime('+2 months +2 days'),
array('end' => '1 month', 'format' => '%x')
);
$this->assertEquals('on ' . strftime('%x', strtotime('+2 months +2 days')), $result);
// @codingStandardsIgnoreStart
$this->assertEquals('on ' . @strftime('%x', strtotime('+2 months +2 days')), $result);
// @codingStandardsIgnoreEnd
}

/**
Expand Down Expand Up @@ -1174,7 +1178,9 @@ public function testI18nFormat() {
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, '%c');
$expected = 'jue 14 ene 2010 13:59:28 ' . utf8_encode(strftime('%Z', $time));
// @codingStandardsIgnoreStart
$expected = 'jue 14 ene 2010 13:59:28 ' . mb_convert_encoding(@strftime('%Z', $time), 'UTF-8', 'ISO-8859-1');
// @codingStandardsIgnoreEnd
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x');
Expand All @@ -1188,7 +1194,9 @@ public function testI18nFormat() {
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, '%c');
$expected = 'mié 13 ene 2010 13:59:28 ' . utf8_encode(strftime('%Z', $time));
// @codingStandardsIgnoreStart
$expected = 'mié 13 ene 2010 13:59:28 ' . mb_convert_encoding(@strftime('%Z', $time), 'UTF-8', 'ISO-8859-1');
// @codingStandardsIgnoreEnd
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x');
Expand Down
6 changes: 4 additions & 2 deletions lib/Cake/Utility/CakeTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,9 @@ public static function listTimezones($filter = null, $country = null, $options =
* @return string formatted string with correct encoding.
*/
protected static function _strftime($format, $timestamp) {
$format = strftime($format, $timestamp);
// @codingStandardsIgnoreStart
$format = @strftime($format, $timestamp);
// @codingStandardsIgnoreEnd
$encoding = Configure::read('App.encoding');
if (!empty($encoding) && $encoding === 'UTF-8') {
if (function_exists('mb_check_encoding')) {
Expand All @@ -1176,7 +1178,7 @@ protected static function _strftime($format, $timestamp) {
$valid = Multibyte::checkMultibyte($format);
}
if (!$valid) {
$format = utf8_encode($format);
$format = mb_convert_encoding($format, 'UTF-8', 'ISO-8859-1');
}
}
return $format;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public function setEntity($entity, $setScope = false) {
* @return array An array containing the identity elements of an entity
*/
public function entity() {
return explode('.', $this->_entityPath);
return explode('.', (string)$this->_entityPath);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
}

$selects = array();
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
foreach (preg_split('//', (string)$dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
switch ($char) {
case 'Y':
$attrs['Year']['value'] = $year;
Expand Down Expand Up @@ -2767,7 +2767,9 @@ protected function _getDateTimeValue($value, $timeFormat) {
}

if (is_numeric($value)) {
$value = strftime('%Y-%m-%d %H:%M:%S', $value);
// @codingStandardsIgnoreStart
$value = @strftime('%Y-%m-%d %H:%M:%S', $value);
// @codingStandardsIgnoreEnd
}
$meridian = 'am';
$pos = strpos($value, '-');
Expand Down Expand Up @@ -3021,7 +3023,9 @@ protected function _generateOptions($name, $options = array()) {
$data = $options['monthNames'];
} else {
for ($m = 1; $m <= 12; $m++) {
$data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1, 1999));
// @codingStandardsIgnoreStart
$data[sprintf("%02s", $m)] = @strftime("%m", mktime(1, 1, 1, $m, 1, 1999));
// @codingStandardsIgnoreEnd
}
}
break;
Expand Down
Loading