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 warning on PHP8 #1077

Merged
merged 8 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions data/class/SC_CartSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getNextCartID($product_type_id)
{
$count = [];
foreach ($this->cartSession[$product_type_id] as $key => $value) {
$count[] = $this->cartSession[$product_type_id][$key]['cart_no'];
$count[] = $this->cartSession[$product_type_id][$key]['cart_no'] ?? null;
}

return max($count) + 1;
Expand Down Expand Up @@ -147,7 +147,8 @@ public function getMax($product_type_id)
{
$max = 0;
if (
is_array($this->cartSession[$product_type_id])
isset($this->cartSession[$product_type_id])
&& is_array($this->cartSession[$product_type_id])
&& count($this->cartSession[$product_type_id]) > 0
) {
foreach ($this->cartSession[$product_type_id] as $key => $value) {
Expand All @@ -157,6 +158,24 @@ public function getMax($product_type_id)
}
}
}
} else {
$this->cartSession[$product_type_id] = [];
}

// カート内商品の最大要素番号までの要素が存在しない場合、要素を追加しておく
for ($i = 0; $i <= $max; $i++) {
if (!array_key_exists($i, $this->cartSession[$product_type_id])) {
$this->cartSession[$product_type_id][$i] = [
'id' => null,
'cart_no' => null,
'price' => 0,
'quantity' => 0,
'productsClass' => [
'product_id' => null,
'product_class_id' => null,
],
];
}
}

return $max;
Expand Down Expand Up @@ -261,7 +280,7 @@ public function addProduct($product_class_id, $quantity)
{
$objProduct = new SC_Product_Ex();
$arrProduct = $objProduct->getProductsClass($product_class_id);
$product_type_id = $arrProduct['product_type_id'];
$product_type_id = $arrProduct['product_type_id'] ?? null;
$find = false;
$max = $this->getMax($product_type_id);
for ($i = 0; $i <= $max; $i++) {
Expand Down Expand Up @@ -875,7 +894,7 @@ public function unsetKey()
*/
public function getKey()
{
return $_SESSION['cartKey'];
return $_SESSION['cartKey'] ?? null;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions data/class/SC_CheckError.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function EXIST_CHECK($value)

$this->createParam($value);

$input_var = $this->arrParam[$keyname];
$input_var = $this->arrParam[$keyname] ?? '';
if (is_array($input_var)) {
if (count($input_var) == 0) {
$this->arrErr[$keyname] =
Expand Down Expand Up @@ -304,7 +304,7 @@ public function EQUAL_CHECK($value)
// $this->createParam($value);

// 文字数の取得
if ($this->arrParam[$keyname1] !== $this->arrParam[$keyname2]) {
if (($this->arrParam[$keyname1] ?? '') !== ($this->arrParam[$keyname2] ?? '')) {
$this->arrErr[$keyname1] =
"※{$disp_name1}と{$disp_name2}が一致しません。<br />";
}
Expand Down Expand Up @@ -338,7 +338,7 @@ public function DIFFERENT_CHECK($value)
// $this->createParam($value);

// 文字数の取得
if ($this->arrParam[$keyname1] == $this->arrParam[$keyname2]) {
if (($this->arrParam[$keyname1] ?? '') == ($this->arrParam[$keyname2] ?? '')) {
$this->arrErr[$keyname1] = sprintf(
'※ %sと%sは、同じ値を使用できません。<br />',
$disp_name1,
Expand Down Expand Up @@ -375,8 +375,8 @@ public function GREATER_CHECK($value)
// $this->createParam($value);

// 文字数の取得
$input_var1 = $this->arrParam[$keyname1];
$input_var2 = $this->arrParam[$keyname2];
$input_var1 = $this->arrParam[$keyname1] ?? '';
$input_var2 = $this->arrParam[$keyname2] ?? '';
if ($input_var1 != ''
&& $input_var2 != ''
&& ($input_var1 > $input_var2)
Expand Down Expand Up @@ -1221,7 +1221,7 @@ public function FILE_SIZE_CHECK($value)

$this->createParam($value);

if ($_FILES[$keyname]['size'] > $max_file_size * 1024) {
if (isset($_FILES[$keyname]['size']) && $_FILES[$keyname]['size'] > $max_file_size * 1024) {
$byte = 'KB';
if ($max_file_size >= 1000) {
$max_file_size /= 1000;
Expand Down Expand Up @@ -1475,7 +1475,7 @@ public function CHECK_SET_TERM($value)
$date1 = sprintf('%d%02d%02d000000', $start_year, $start_month, $start_day);
$date2 = sprintf('%d%02d%02d235959', $end_year, $end_month, $end_day);

if (($this->arrErr[$keyname1] == '' && $this->arrErr[$keyname2] == '') && $date1 > $date2) {
if ((!isset($this->arrErr[$keyname1]) && !isset($this->arrErr[$keyname2])) && $date1 > $date2) {
$this->arrErr[$keyname1] =
"※ {$disp_name1}と{$disp_name2}の期間指定が不正です。<br />";
}
Expand Down Expand Up @@ -1556,7 +1556,7 @@ public function CHECK_SET_TERM2($value)
$end_year, $end_month, $end_day,
$end_hour, $end_minute, $end_second);

if (($this->arrErr[$keyname1] == '' && $this->arrErr[$keyname2] == '') && $date1 > $date2) {
if ((!isset($this->arrErr[$keyname1]) && !isset($this->arrErr[$keyname2])) && $date1 > $date2) {
$this->arrErr[$keyname1] =
"※ {$disp_name1}と{$disp_name2}の期間指定が不正です。<br />";
}
Expand Down Expand Up @@ -1616,7 +1616,7 @@ public function CHECK_SET_TERM3($value)
$date1 = sprintf('%d%02d', $start_year, $start_month);
$date2 = sprintf('%d%02d', $end_year, $end_month);

if (($this->arrErr[$keyname1] == '' && $this->arrErr[$keyname2] == '') && $date1 > $date2) {
if ((!isset($this->arrErr[$keyname1]) && !isset($this->arrErr[$keyname2])) && $date1 > $date2) {
$this->arrErr[$keyname1] =
"※ {$disp_name1}と{$disp_name2}の期間指定が不正です。<br />";
}
Expand Down
8 changes: 6 additions & 2 deletions data/class/SC_ClassAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@

eval($base_class_str);
} else {
include $plugin_classpath;
if (file_exists($plugin_classpath)) {
include $plugin_classpath;
}
}

$parent_classname = $plugin_class;
} else {
include $plugin_classpath;
if (file_exists($plugin_classpath)) {
include $plugin_classpath;

Check warning on line 117 in data/class/SC_ClassAutoloader.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_ClassAutoloader.php#L116-L117

Added lines #L116 - L117 were not covered by tests
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions data/class/SC_Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function startSession()
{
$_SESSION['customer'] = $this->customer_data;
// セッション情報の保存
GC_Utils_Ex::gfPrintLog('access : user='.$this->customer_data['customer_id']."\t".'ip='.$this->getRemoteHost(), CUSTOMER_LOG_REALFILE, false);
GC_Utils_Ex::gfPrintLog('access : user='.($this->customer_data['customer_id'] ?? '')."\t".'ip='.$this->getRemoteHost(), CUSTOMER_LOG_REALFILE, false);
}

/**
Expand Down Expand Up @@ -270,9 +270,12 @@ public function getValue($keyname)
{
// ポイントはリアルタイム表示
if ($keyname == 'point') {
$objQuery = SC_Query_Ex::getSingletonInstance();
$point = $objQuery->get('point', 'dtb_customer', 'customer_id = ?', [$_SESSION['customer']['customer_id']]);
$_SESSION['customer']['point'] = $point;
$point = 0;
if (isset($_SESSION['customer']['customer_id'])) {
$objQuery = SC_Query_Ex::getSingletonInstance();
$point = $objQuery->get('point', 'dtb_customer', 'customer_id = ?', [$_SESSION['customer']['customer_id']]);
$_SESSION['customer']['point'] = $point;
}

return $point;
} else {
Expand Down
4 changes: 2 additions & 2 deletions data/class/SC_CustomerList.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function __construct($array, $mode = '')
foreach ($this->arrSql['search_email'] as $val) {
$val = trim($val);
// 検索条件を含まない
if ($this->arrSql['not_emailinc'] == '1') {
if (isset($this->arrSql['not_emailinc']) && $this->arrSql['not_emailinc'] == '1') {
if ($sql_where == '') {
$sql_where .= 'dtb_customer.email NOT ILIKE ? ';
} else {
Expand Down Expand Up @@ -173,7 +173,7 @@ public function __construct($array, $mode = '')
foreach ($this->arrSql['search_email_mobile'] as $val) {
$val = trim($val);
// 検索条件を含まない
if ($this->arrSql['not_email_mobileinc'] == '1') {
if (isset($this->arrSql['not_email_mobileinc']) && $this->arrSql['not_email_mobileinc'] == '1') {
if ($sql_where == '') {
$sql_where .= 'dtb_customer.email_mobile NOT ILIKE ? ';
} else {
Expand Down
34 changes: 18 additions & 16 deletions data/class/SC_Initial.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public function __construct()
{
/* EC-CUBEのバージョン */
define('ECCUBE_VERSION', '2.17.2-p2');
defined('ECCUBE_VERSION') || define('ECCUBE_VERSION', '2.17.2-p2');

Check warning on line 39 in data/class/SC_Initial.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Initial.php#L39

Added line #L39 was not covered by tests
}

/**
Expand Down Expand Up @@ -72,7 +72,9 @@

// heroku用
} elseif (getenv('DATABASE_URL')) {
ini_set('display_errors', 1);
if (!headers_sent()) {
ini_set('display_errors', 1);

Check warning on line 76 in data/class/SC_Initial.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Initial.php#L75-L76

Added lines #L75 - L76 were not covered by tests
}
copy(realpath(__DIR__).'/../../tests/config.php', CONFIG_REALFILE);

require_once CONFIG_REALFILE;
Expand Down Expand Up @@ -139,26 +141,26 @@
*/
public function phpconfigInit()
{
ini_set('html_errors', '1');
if (PHP_VERSION_ID < 50600) {
ini_set('mbstring.http_input', CHAR_CODE);
ini_set('mbstring.http_output', CHAR_CODE);
}
if (PHP_VERSION_ID < 80100) {
ini_set('auto_detect_line_endings', 1);
if (!headers_sent()) {
ini_set('html_errors', '1');

Check warning on line 145 in data/class/SC_Initial.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Initial.php#L144-L145

Added lines #L144 - L145 were not covered by tests
if (PHP_VERSION_ID < 50600) {
ini_set('mbstring.http_input', CHAR_CODE);
ini_set('mbstring.http_output', CHAR_CODE);
}
if (PHP_VERSION_ID < 80100) {
ini_set('auto_detect_line_endings', 1);

Check warning on line 151 in data/class/SC_Initial.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Initial.php#L151

Added line #L151 was not covered by tests
}
ini_set('default_charset', CHAR_CODE);
ini_set('mbstring.detect_order', 'auto');
ini_set('mbstring.substitute_character', 'none');
ini_set('pcre.backtrack_limit', 1000000);
ini_set('arg_separator.output', '&');

Check warning on line 157 in data/class/SC_Initial.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Initial.php#L153-L157

Added lines #L153 - L157 were not covered by tests
}
ini_set('default_charset', CHAR_CODE);
ini_set('mbstring.detect_order', 'auto');
ini_set('mbstring.substitute_character', 'none');
ini_set('pcre.backtrack_limit', 1000000);

mb_language('ja'); // mb_internal_encoding() より前に
// TODO .htaccess の mbstring.language を削除できないか検討

mb_internal_encoding(CHAR_CODE); // mb_language() より後で

ini_set('arg_separator.output', '&');

// ロケールを明示的に設定
$res = setlocale(LC_ALL, LOCALE);
if ($res === false) {
Expand Down
10 changes: 5 additions & 5 deletions data/class/SC_Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function getDetail($product_id)
public function getDetailAndProductsClass($productClassId)
{
$result = $this->getProductsClass($productClassId);
$result = array_merge($result, $this->getDetail($result['product_id']));
$result = array_merge($result, $this->getDetail($result['product_id'] ?? null));

return $result;
}
Expand Down Expand Up @@ -423,13 +423,13 @@ public function getProductsClass($productClassId)
$objQuery->setWhere('product_class_id = ? AND T1.del_flg = 0');
$arrRes = $this->getProductsClassByQuery($objQuery, $productClassId);

$arrProduct = (array) $arrRes[0];
$arrProduct = $arrRes[0] ?? [];

// 税込計算
if (!SC_Utils_Ex::isBlank($arrProduct['price01'])) {
if (!SC_Utils_Ex::isBlank($arrProduct['price01'] ?? '')) {
$arrProduct['price01_inctax'] = SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price01'], $arrProduct['product_id']);
}
if (!SC_Utils_Ex::isBlank($arrProduct['price02'])) {
if (!SC_Utils_Ex::isBlank($arrProduct['price02'] ?? '')) {
$arrProduct['price02_inctax'] = SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price02'], $arrProduct['product_id']);
}

Expand Down Expand Up @@ -577,7 +577,7 @@ public function reduceStock($productClassId, $quantity)
// TODO エラーハンドリング

$productsClass = $this->getDetailAndProductsClass($productClassId);
if ($productsClass['stock_unlimited'] != '1' && $productsClass['stock'] < 0) {
if (($productsClass['stock_unlimited'] ?? 0) != '1' && ($productsClass['stock'] ?? 0) < 0) {
return false;
}

Expand Down
19 changes: 13 additions & 6 deletions data/class/SC_Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@

public function sendHeader()
{
if (headers_sent()) {
return;
}
// HTTPのヘッダ
foreach ($this->header as $name => $head) {
header($name.': '.$head);
Expand Down Expand Up @@ -177,7 +180,7 @@
}

// url-path → URL 変換
if ($location[0] === '/') {
if ($location !== '' && $location[0] === '/') {
$netUrl = new Net_URL($location);
$location = $netUrl->getUrl();
}
Expand Down Expand Up @@ -248,7 +251,9 @@

$url = $netUrl->getURL();

header("Location: $url");
if (!headers_sent()) {
header("Location: $url");

Check warning on line 255 in data/class/SC_Response.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Response.php#L255

Added line #L255 was not covered by tests
}
static::exitWrapper();
}

Expand Down Expand Up @@ -388,10 +393,12 @@
*/
public static function headerForDownload($file_name)
{
header("Content-disposition: attachment; filename={$file_name}");
header("Content-type: application/octet-stream; name={$file_name}");
header('Cache-Control: ');
header('Pragma: ');
if (!headers_sent()) {
header("Content-disposition: attachment; filename={$file_name}");
header("Content-type: application/octet-stream; name={$file_name}");
header('Cache-Control: ');
header('Pragma: ');

Check warning on line 400 in data/class/SC_Response.php

View check run for this annotation

Codecov / codecov/patch

data/class/SC_Response.php#L397-L400

Added lines #L397 - L400 were not covered by tests
}
}

/**
Expand Down
Loading
Loading