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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ jobs:
FORCE_COLOR: 1
run: yarn ${PATTERN} e2e-tests/${GROUP}

- name: Print error log
if: always()
continue-on-error: true
run: docker compose exec ec-cube tail -n 100 data/logs/error.log

- name: Upload evidence
if: failure()
uses: actions/upload-artifact@v4
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ jobs:
- name: Run to PHPUnit SessionFactory
run: docker compose exec -T ec-cube php data/vendor/bin/phpunit tests/class/SC_SessionFactoryTest.php

- name: Print error log
if: always()
continue-on-error: true
run: docker compose exec ec-cube tail -n 100 data/logs/error.log

- name: Upload logs
if: failure()
uses: actions/upload-artifact@v4
Expand Down
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 @@ -874,7 +893,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 = $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 @@ public static function autoload($class, $plugin_upload_realdir = PLUGIN_UPLOAD_R

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;
}
}
}

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 @@ class SC_Initial
public function __construct()
{
/* EC-CUBEのバージョン */
define('ECCUBE_VERSION', '2.17.2-p2');
defined('ECCUBE_VERSION') or define('ECCUBE_VERSION', '2.17.2-p2');
}

/**
Expand Down Expand Up @@ -73,7 +73,9 @@ public function requireInitialConfig()

// heroku用
} elseif (getenv('DATABASE_URL')) {
ini_set('display_errors', 1);
if (!headers_sent()) {
ini_set('display_errors', 1);
}
copy(realpath(__DIR__).'/../../tests/config.php', CONFIG_REALFILE);

require_once CONFIG_REALFILE;
Expand Down Expand Up @@ -140,26 +142,26 @@ public function setErrorReporting()
*/
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');
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);
}
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', '&');
}
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
Loading
Loading