Skip to content

Commit

Permalink
[php82] fix several notices
Browse files Browse the repository at this point in the history
  • Loading branch information
beinbm committed Aug 10, 2023
1 parent 62b703a commit c630799
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Console/ShellDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public function parseParams($args) {
$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
$isWin = false;
foreach ($defaults as $default => $value) {
if (strpos($params[$default], '\\') !== false) {
if (strpos((string)$params[$default], '\\') !== false) {
$isWin = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static function translate($singular, $plural = null, $domain = null, $cat
$_this->domain = $domain . '_' . $_this->l10n->lang;

if (!isset($_this->_domains[$domain][$_this->_lang])) {
$_this->_domains[$domain][$_this->_lang] = Cache::read($_this->domain, '_cake_core_');
$_this->_domains[$domain][$_this->_lang] = Cache::read($_this->domain, '_cake_core_') ?: [];
}

if (!isset($_this->_domains[$domain][$_this->_lang][$_this->category])) {
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Model/Behavior/ContainableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public function containments(Model $Model, $contain, $containments = array(), $t
*/
public function fieldDependencies(Model $Model, $map, $fields = array()) {
if ($fields === false) {
$fields = [];
foreach ($map as $parent => $children) {
foreach ($children as $type => $bindings) {
foreach ($bindings as $dependency) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function describe($model) {
);

foreach ($result as $column) {
$default = ($column['dflt_value'] === 'NULL') ? null : trim($column['dflt_value'], "'");
$default = ($column['dflt_value'] === 'NULL') ? null : trim((string) $column['dflt_value'], "'");

$fields[$column['name']] = array(
'type' => $this->column($column['type']),
Expand Down
57 changes: 31 additions & 26 deletions lib/Cake/Network/CakeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function _processGet() {
unset($query[$unsetUrl]);
unset($query[$this->base . $unsetUrl]);
if (strpos($this->url, '?') !== false) {
list($this->url, $querystr) = explode('?', $this->url);
[$this->url, $querystr] = explode('?', $this->url);
parse_str($querystr, $queryArgs);
$query += $queryArgs;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ protected function _url() {
$uri = substr($uri, strlen($base));
}
if (strpos($uri, '?') !== false) {
list($uri) = explode('?', $uri, 2);
[$uri] = explode('?', $uri, 2);
}
if (empty($uri) || $uri === '/' || $uri === '//' || $uri === '/index.php') {
$uri = '/';
Expand Down Expand Up @@ -919,7 +919,7 @@ public static function acceptLanguage($language = null) {
*/
protected static function _parseAcceptWithQualifier($header) {
$accept = array();
$header = explode(',', $header);
$header = explode(',', (string) $header);
foreach (array_filter($header) as $value) {
$prefValue = '1.0';
$value = trim($value);
Expand Down Expand Up @@ -1043,7 +1043,8 @@ public function input($callback = null) {
* @param string $input A string to replace original parsed data from input()
* @return void
*/
public function setInput($input) {
public function setInput($input): void
{
$this->_input = $input;
}

Expand All @@ -1064,7 +1065,8 @@ public function setInput($input) {
* @return bool true
* @throws MethodNotAllowedException
*/
public function allowMethod($methods) {
public function allowMethod($methods): bool
{
if (!is_array($methods)) {
$methods = func_get_args();
}
Expand All @@ -1088,7 +1090,8 @@ public function allowMethod($methods) {
* @see CakeRequest::allowMethod()
* @deprecated 3.0.0 Since 2.5, use CakeRequest::allowMethod() instead.
*/
public function onlyAllow($methods) {
public function onlyAllow($methods): bool
{
if (!is_array($methods)) {
$methods = func_get_args();
}
Expand All @@ -1100,9 +1103,10 @@ public function onlyAllow($methods) {
*
* @return string contents of php://input
*/
protected function _readInput() {
protected function _readInput(): string
{
if (empty($this->_input)) {
$fh = fopen('php://input', 'r');
$fh = fopen('php://input', 'rb');
$content = stream_get_contents($fh);
fclose($fh);
$this->_input = $content;
Expand All @@ -1113,17 +1117,18 @@ protected function _readInput() {
/**
* Array access read implementation
*
* @param mixed $name Name of the key being accessed.
* @param mixed $offset Name of the key being accessed.
* @return mixed
*/
public function offsetGet( $name) {
if (isset($this->params[$name])) {
return $this->params[$name];
public function offsetGet(mixed $offset): mixed
{
if (isset($this->params[$offset])) {
return $this->params[$offset];
}
if ($name === 'url') {
if ($offset === 'url') {
return $this->query;
}
if ($name === 'data') {
if ($offset === 'data') {
return $this->data;
}
return null;
Expand All @@ -1132,35 +1137,35 @@ public function offsetGet( $name) {
/**
* Array access write implementation
*
* @param string $name Name of the key being written
* @param string $offset Name of the key being written
* @param mixed $value The value being written.
* @return void
*/
public function offsetSet($name, $value) {
$this->params[$name] = $value;
public function offsetSet($offset, mixed $value): void {
$this->params[$offset] = $value;
}

/**
* Array access isset() implementation
*
* @param string $name thing to check.
* @param string $offset thing to check.
* @return bool
*/
public function offsetExists($name) {
if ($name === 'url' || $name === 'data') {
public function offsetExists(mixed $offset): bool {
if ($offset === 'url' || $offset === 'data') {
return true;
}
return isset($this->params[$name]);
}
return isset($this->params[$offset]);
}

/**
/**
* Array access unset() implementation
*
* @param string $name Name to unset.
* @param string $offset Name to unset.
* @return void
*/
public function offsetUnset($name) {
unset($this->params[$name]);
public function offsetUnset($offset): void {
unset($this->params[$offset]);
}

}
12 changes: 9 additions & 3 deletions lib/Cake/TestSuite/CakeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ abstract class CakeTestCase extends \PHPUnit\Framework\TestCase {
*/
public $dropTables = true;

/**
/**
* was a dynamic property before
* @var DataSource|null
*/
public ?DataSource $db;

/**
* Configure values to restore at end of test.
*
* @var array
Expand Down Expand Up @@ -485,7 +491,7 @@ public function assertTags($string, $expected, $fullDebug = false) {
continue;
}

list($description, $expressions, $itemNum) = $assertion;
[$description, $expressions, $itemNum] = $assertion;
foreach ((array)$expressions as $expression) {
if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) {
$matches = true;
Expand Down Expand Up @@ -814,7 +820,7 @@ public function getMockForModel($model, $methods = array(), $config = array()) {
$defaults = ClassRegistry::config('Model');
unset($defaults['ds']);

list($plugin, $name) = pluginSplit($model, true);
[$plugin, $name] = pluginSplit($model, true);
App::uses($name, $plugin . 'Model');

$config = array_merge($defaults, (array)$config, array('name' => $name));
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public static function check(array $data, $path) {
* @return array Filtered array
* @link https://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::filter
*/
public static function filter(array $data, $callback = array('self', '_filter')) {
public static function filter(array $data, $callback = array(self::class, '_filter')) {
foreach ($data as $k => $v) {
if (is_array($v)) {
$data[$k] = static::filter($v, $callback);
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/View/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ protected function _confirm($message, $okCode, $cancelCode = '', $options = arra
public function setEntity($entity, $setScope = false) {
if ($entity === null) {
$this->_modelScope = false;
return;
}
if ($setScope === true) {
$this->_modelScope = $entity;
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ public function day($fieldName = null, $attributes = array()) {
$attributes += array('empty' => true, 'value' => null);
$attributes = $this->_dateTimeSelected('day', $fieldName, $attributes);

if (strlen($attributes['value']) > 2) {
if (strlen((string) $attributes['value']) > 2) {
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
Expand Down Expand Up @@ -2396,7 +2396,7 @@ public function month($fieldName, $attributes = array()) {
$attributes += array('empty' => true, 'value' => null);
$attributes = $this->_dateTimeSelected('month', $fieldName, $attributes);

if (strlen($attributes['value']) > 2) {
if (strlen((string)$attributes['value']) > 2) {
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
Expand Down Expand Up @@ -2767,7 +2767,7 @@ protected function _getDateTimeValue($value, $timeFormat) {
}

if (is_numeric($value)) {
$value = strftime('%Y-%m-%d %H:%M:%S', $value);
$value = date('Y-m-d H:i:s', $value);
}
$meridian = 'am';
$pos = strpos($value, '-');
Expand Down

0 comments on commit c630799

Please sign in to comment.