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 1 commit
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
Prev Previous commit
Next Next commit
Fix warning
PHPUnit で出る Warning 解消
  • Loading branch information
nanasess committed Dec 13, 2024
commit 76aefc6b343f8ea132dd600e5c680eb679ce0ce1
4 changes: 2 additions & 2 deletions data/class/SC_CartSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,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 @@ -893,7 +893,7 @@ public function unsetKey()
*/
public function getKey()
{
return $_SESSION['cartKey'];
return $_SESSION['cartKey'] ?? null;
}

/**
Expand Down
16 changes: 8 additions & 8 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 @@ -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
2 changes: 1 addition & 1 deletion 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
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
17 changes: 12 additions & 5 deletions data/class/SC_Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function write()

public function sendHeader()
{
if (headers_sent()) {
return;
}
// HTTPのヘッダ
foreach ($this->header as $name => $head) {
header($name.': '.$head);
Expand Down Expand Up @@ -247,7 +250,9 @@ public static function sendRedirect($location, $arrQueryString = [], $inheritQue

$url = $netUrl->getURL();

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

Expand Down Expand Up @@ -385,10 +390,12 @@ public static function sendHttpStatus($statusCode)
*/
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: ');
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions data/class/SC_UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function makeTempDownFile($keyname = 'down_file')
}
}

return $objErr->arrErr[$keyname];
return $objErr->arrErr[$keyname] ?? '';
}

// 画像を削除する。
Expand Down Expand Up @@ -506,7 +506,7 @@ public function deleteDBDownFile($arrVal)
$objImage = new SC_Image_Ex($this->temp_dir);
$cnt = 0;
if ($arrVal['down_realfilename'] != '') {
if ($this->save_file[$cnt] == '' && !preg_match('|^sub/|', $arrVal['down_realfilename'])) {
if (!isset($this->save_file[$cnt]) && !preg_match('|^sub/|', $arrVal['down_realfilename'])) {
$objImage->deleteImage($arrVal['down_realfilename'], $this->save_dir);
}
}
Expand Down
12 changes: 6 additions & 6 deletions data/class/helper/SC_Helper_BestProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static function getBestProducts($best_id, $has_deleted = false)
if (!$has_deleted) {
$where .= ' AND del_flg = 0';
}
$arrRet = $objQuery->select($col, 'dtb_best_products', $where, [$best_id]);
$arrRet = $objQuery->getRow($col, 'dtb_best_products', $where, [$best_id]);

return $arrRet[0];
return $arrRet;
}

/**
Expand All @@ -67,9 +67,9 @@ public static function getByRank($rank, $has_deleted = false)
if (!$has_deleted) {
$where .= ' AND del_flg = 0';
}
$arrRet = $objQuery->select($col, 'dtb_best_products', $where, [$rank]);
$arrRet = $objQuery->getRow($col, 'dtb_best_products', $where, [$rank]);

return $arrRet[0];
return $arrRet;
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ public static function rankUp($best_id)
if ($rank > 1) {
// 表示順が一つ上のIDを取得する
$arrAboveBestProducts = static::getByRank($rank - 1);
$above_best_id = $arrAboveBestProducts['best_id'];
$above_best_id = $arrAboveBestProducts['best_id'] ?? null;

if ($above_best_id) {
// 一つ上のものを一つ下に下げる
Expand Down Expand Up @@ -215,7 +215,7 @@ public static function rankDown($best_id)
if ($rank < RECOMMEND_NUM) {
// 表示順が一つ下のIDを取得する
$arrBelowBestProducts = static::getByRank($rank + 1);
$below_best_id = $arrBelowBestProducts['best_id'];
$below_best_id = $arrBelowBestProducts['best_id'] ?? null;

if ($below_best_id) {
// 一つ下のものを一つ上に上げる
Expand Down
4 changes: 2 additions & 2 deletions data/class/helper/SC_Helper_Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function sfEditCustomerData($arrData, $customer_id = null)
}
$is_password_updated = false;
// -- パスワードの更新がある場合は暗号化
if ($arrData['password'] == DEFAULT_PASSWORD || $arrData['password'] == '') {
if (!isset($arrData['password']) || $arrData['password'] == DEFAULT_PASSWORD) {
// 更新しない
unset($arrData['password']);
} else {
Expand All @@ -75,7 +75,7 @@ public static function sfEditCustomerData($arrData, $customer_id = null)
$arrData['password'] = SC_Utils_Ex::sfGetHashString($arrData['password'], $salt);
}
// -- 秘密の質問の更新がある場合は暗号化
if ($arrData['reminder_answer'] == DEFAULT_PASSWORD || $arrData['reminder_answer'] == '') {
if (!isset($arrData['reminder_answer']) || $arrData['reminder_answer'] == DEFAULT_PASSWORD) {
// 更新しない
unset($arrData['reminder_answer']);

Expand Down
12 changes: 9 additions & 3 deletions data/class/helper/SC_Helper_HandleError.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public static function load()
// E_USER_ERROR 以外のエラーを捕捉した場合の処理用
register_shutdown_function([__CLASS__, 'handle_error']);
// 以降の処理では画面へのエラー表示は行なわない
ini_set('display_errors', 0);
if (!headers_sent()) {
ini_set('display_errors', 0);
}
}
}

Expand Down Expand Up @@ -103,7 +105,9 @@ public static function handle_warning($errno, $errstr, $errfile, $errline)
case E_USER_ERROR:
// パラメーターが読み込まれるまでは、エラー例外をスローする。(上の分岐があるため phpunit の実行中に限定される。)
if (!defined('ERROR_LOG_REALFILE')) {
ini_set('display_errors', static::$default_display_errors);
if (!headers_sent()) {
ini_set('display_errors', static::$default_display_errors);
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}

Expand Down Expand Up @@ -197,7 +201,9 @@ public static function handle_error()

// パラメーターが読み込まれるまでは、エラー例外をスローする。
if (!defined('ERROR_LOG_REALFILE')) {
ini_set('display_errors', static::$default_display_errors);
if (!headers_sent()) {
ini_set('display_errors', static::$default_display_errors);
}
throw new ErrorException($arrError['message'], 0, $arrError['type'], $arrError['file'], $arrError['line']);
}

Expand Down
4 changes: 2 additions & 2 deletions data/class/helper/SC_Helper_Kiyaku.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public function getKiyaku($kiyaku_id, $has_deleted = false)
if (!$has_deleted) {
$where .= ' AND del_flg = 0';
}
$arrRet = $objQuery->select('*', 'dtb_kiyaku', $where, [$kiyaku_id]);
$arrRet = $objQuery->getRow('*', 'dtb_kiyaku', $where, [$kiyaku_id]);

return $arrRet[0];
return $arrRet;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions data/class/helper/SC_Helper_Maker.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function getByName($name, $has_deleted = false)
if (!$has_deleted) {
$where .= ' AND del_flg = 0';
}
$arrRet = $objQuery->select('*', 'dtb_maker', $where, [$name]);
$arrRet = $objQuery->getRow('*', 'dtb_maker', $where, [$name]);

return $arrRet[0];
return $arrRet;
}

/**
Expand Down
Loading
Loading