Skip to content

Commit c2b28ee

Browse files
committed
refactor: Apply rector rule
This commit removes redundant `(string)` type casting from multiple methods across the codebase. The changes improve code readability and maintainability without altering functionality.
1 parent bae77c2 commit c2b28ee

File tree

18 files changed

+41
-41
lines changed

18 files changed

+41
-41
lines changed

src/Eccube/Controller/Admin/Content/FileController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function download(Request $request): BinaryFileResponse
257257
if ($this->checkDir($file, $topDir)) {
258258
if (!is_dir($file)) {
259259
setlocale(LC_ALL, 'ja_JP.UTF-8');
260-
$pathParts = pathinfo((string) $file);
260+
$pathParts = pathinfo($file);
261261

262262
$patterns = [
263263
'/[a-zA-Z0-9!"#$%&()=~^|@`:*;+{}]/',
@@ -326,15 +326,15 @@ public function upload(Request $request): void
326326
$filename = $this->convertStrToServer($file->getClientOriginalName());
327327
try {
328328
// フォルダの存在チェック
329-
if (is_dir(rtrim((string) $nowDir, '/\\').\DIRECTORY_SEPARATOR.$filename)) {
329+
if (is_dir(rtrim($nowDir, '/\\').\DIRECTORY_SEPARATOR.$filename)) {
330330
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.same_name_folder_exists'));
331331
}
332332
// 英数字, 半角スペース, _-.() のみ許可
333-
if (!preg_match('/\A[a-zA-Z0-9_\-\.\(\) ]+\Z/', (string) $filename)) {
333+
if (!preg_match('/\A[a-zA-Z0-9_\-\.\(\) ]+\Z/', $filename)) {
334334
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.folder_name_symbol_error'));
335335
}
336336
// dotファイルはアップロード不可
337-
if (str_starts_with((string) $filename, '.')) {
337+
if (str_starts_with($filename, '.')) {
338338
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.dotfile_error'));
339339
}
340340
// 許可した拡張子以外アップロード不可

src/Eccube/Controller/Admin/Product/CsvImportController.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function csvProduct(Request $request, CacheUtil $cacheUtil): array|JsonRe
260260
$Product = new Product();
261261
$this->entityManager->persist($Product);
262262
} else {
263-
if (preg_match('/^\d+$/', (string) $row[$headerByKey['id']])) {
263+
if (preg_match('/^\d+$/', $row[$headerByKey['id']])) {
264264
$Product = $this->productRepository->find($row[$headerByKey['id']]);
265265
if (!$Product) {
266266
$message = trans('admin.common.csv_invalid_not_found', ['%line%' => $line, '%name%' => $headerByKey['id']]);
@@ -299,7 +299,7 @@ public function csvProduct(Request $request, CacheUtil $cacheUtil): array|JsonRe
299299
$message = trans('admin.common.csv_invalid_required', ['%line%' => $line, '%name%' => $headerByKey['status']]);
300300
$this->addErrors($message);
301301
} else {
302-
if (preg_match('/^\d+$/', (string) $row[$headerByKey['status']])) {
302+
if (preg_match('/^\d+$/', $row[$headerByKey['status']])) {
303303
$ProductStatus = $this->productStatusRepository->find($row[$headerByKey['status']]);
304304
if (!$ProductStatus) {
305305
$message = trans('admin.common.csv_invalid_not_found', ['%line%' => $line, '%name%' => $headerByKey['status']]);
@@ -340,7 +340,7 @@ public function csvProduct(Request $request, CacheUtil $cacheUtil): array|JsonRe
340340

341341
if (isset($row[$headerByKey['description_detail']])) {
342342
if (StringUtil::isNotBlank($row[$headerByKey['description_detail']])) {
343-
if (mb_strlen((string) $row[$headerByKey['description_detail']]) > $this->eccubeConfig['eccube_ltext_len']) {
343+
if (mb_strlen($row[$headerByKey['description_detail']]) > $this->eccubeConfig['eccube_ltext_len']) {
344344
$message = trans('admin.common.csv_invalid_description_detail_upper_limit', [
345345
'%line%' => $line,
346346
'%name%' => $headerByKey['description_detail'],
@@ -452,7 +452,7 @@ public function csvProduct(Request $request, CacheUtil $cacheUtil): array|JsonRe
452452

453453
// 規格分類1、2をそれぞれセットし作成
454454
$ClassCategory1 = null;
455-
if (preg_match('/^\d+$/', (string) $row[$headerByKey['class_category1']])) {
455+
if (preg_match('/^\d+$/', $row[$headerByKey['class_category1']])) {
456456
$ClassCategory1 = $this->classCategoryRepository->find($row[$headerByKey['class_category1']]);
457457
if (!$ClassCategory1) {
458458
$message = trans('admin.common.csv_invalid_not_found', ['%line%' => $line, '%name%' => $headerByKey['class_category1']]);
@@ -466,7 +466,7 @@ public function csvProduct(Request $request, CacheUtil $cacheUtil): array|JsonRe
466466
}
467467

468468
if (isset($row[$headerByKey['class_category2']]) && StringUtil::isNotBlank($row[$headerByKey['class_category2']])) {
469-
if (preg_match('/^\d+$/', (string) $row[$headerByKey['class_category2']])) {
469+
if (preg_match('/^\d+$/', $row[$headerByKey['class_category2']])) {
470470
$ClassCategory2 = $this->classCategoryRepository->find($row[$headerByKey['class_category2']]);
471471
if (!$ClassCategory2) {
472472
$message = trans('admin.common.csv_invalid_not_found', ['%line%' => $line, '%name%' => $headerByKey['class_category2']]);
@@ -766,8 +766,8 @@ public function csvCategory(Request $request, CacheUtil $cacheUtil): array|JsonR
766766
foreach ($data as $row) {
767767
/** @var Category $Category */
768768
$Category = new Category();
769-
if (isset($row[$headerByKey['id']]) && strlen((string) $row[$headerByKey['id']]) > 0) {
770-
if (!preg_match('/^\d+$/', (string) $row[$headerByKey['id']])) {
769+
if (isset($row[$headerByKey['id']]) && strlen($row[$headerByKey['id']]) > 0) {
770+
if (!preg_match('/^\d+$/', $row[$headerByKey['id']])) {
771771
$this->addErrors(($data->key() + 1).'行目のカテゴリIDが存在しません。');
772772

773773
return $this->renderWithError($form, $headers);
@@ -815,7 +815,7 @@ public function csvCategory(Request $request, CacheUtil $cacheUtil): array|JsonR
815815

816816
$ParentCategory = null;
817817
if (isset($row[$headerByKey['parent_category_id']]) && StringUtil::isNotBlank($row[$headerByKey['parent_category_id']])) {
818-
if (!preg_match('/^\d+$/', (string) $row[$headerByKey['parent_category_id']])) {
818+
if (!preg_match('/^\d+$/', $row[$headerByKey['parent_category_id']])) {
819819
$this->addErrors(($data->key() + 1).'行目の親カテゴリIDは数字で入力してください。');
820820

821821
return $this->renderWithError($form, $headers);
@@ -933,8 +933,8 @@ public function csvClassName(Request $request, CacheUtil $cacheUtil): array|Json
933933
// dump($row,$headerByKey);exit;
934934
/** @var ClassName $ClassName */
935935
$ClassName = new ClassName();
936-
if (isset($row[$headerByKey['id']]) && strlen((string) $row[$headerByKey['id']]) > 0) {
937-
if (!preg_match('/^\d+$/', (string) $row[$headerByKey['id']])) {
936+
if (isset($row[$headerByKey['id']]) && strlen($row[$headerByKey['id']]) > 0) {
937+
if (!preg_match('/^\d+$/', $row[$headerByKey['id']])) {
938938
$this->addErrors(($data->key() + 1).'行目の規格IDが存在しません。');
939939

940940
return $this->renderWithError($form, $headers);
@@ -1057,8 +1057,8 @@ public function csvClassCategory(Request $request, CacheUtil $cacheUtil): array|
10571057
/** @var ClassCategory $ClassCategory */
10581058
$ClassCategory = new ClassCategory();
10591059

1060-
if (isset($row[$headerByKey['id']]) && strlen((string) $row[$headerByKey['id']]) > 0) {
1061-
if (!preg_match('/^\d+$/', (string) $row[$headerByKey['id']])) {
1060+
if (isset($row[$headerByKey['id']]) && strlen($row[$headerByKey['id']]) > 0) {
1061+
if (!preg_match('/^\d+$/', $row[$headerByKey['id']])) {
10621062
$this->addErrors(($data->key() + 1).'行目の規格分類IDが存在しません。');
10631063

10641064
return $this->renderWithError($form, $headers);
@@ -1071,8 +1071,8 @@ public function csvClassCategory(Request $request, CacheUtil $cacheUtil): array|
10711071
}
10721072
}
10731073

1074-
if (isset($row[$headerByKey['class_name_id']]) && strlen((string) $row[$headerByKey['class_name_id']]) > 0) {
1075-
if (!preg_match('/^\d+$/', (string) $row[$headerByKey['class_name_id']])) {
1074+
if (isset($row[$headerByKey['class_name_id']]) && strlen($row[$headerByKey['class_name_id']]) > 0) {
1075+
if (!preg_match('/^\d+$/', $row[$headerByKey['class_name_id']])) {
10761076
$this->addErrors(($data->key() + 1).'行目の規格IDが存在しません。');
10771077

10781078
return $this->renderWithError($form, $headers);

src/Eccube/Controller/ShoppingController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public function confirm(Request $request): \Symfony\Component\HttpFoundation\Red
370370
}
371371

372372
$response = $PaymentResult->getResponse();
373-
if ($response instanceof Response && ($response->isRedirection() || $response->isSuccessful())) {
373+
if ($response->isRedirection() || $response->isSuccessful()) {
374374
$this->entityManager->flush();
375375

376376
log_info('[注文確認] PaymentMethod::verifyが指定したレスポンスを表示します.');
@@ -901,7 +901,7 @@ protected function executeApply(PaymentMethodInterface $paymentMethod): \Symfony
901901
$this->entityManager->flush();
902902

903903
// dispatcherがresponseを保持している場合はresponseを返す
904-
if ($response instanceof Response && ($response->isRedirection() || $response->isSuccessful())) {
904+
if ($response->isRedirection() || $response->isSuccessful()) {
905905
log_info('[注文処理] PaymentMethod::applyが指定したレスポンスを表示します.');
906906

907907
return $response;
@@ -938,7 +938,7 @@ protected function executeCheckout(PaymentMethodInterface $paymentMethod): \Symf
938938
$PaymentResult = $paymentMethod->checkout();
939939
$response = $PaymentResult->getResponse();
940940
// PaymentResultがresponseを保持している場合はresponseを返す
941-
if ($response instanceof Response && ($response->isRedirection() || $response->isSuccessful())) {
941+
if ($response->isRedirection() || $response->isSuccessful()) {
942942
$this->entityManager->flush();
943943
log_info('[注文処理] PaymentMethod::checkoutが指定したレスポンスを表示します.');
944944

src/Eccube/Doctrine/EventSubscriber/TaxRuleEventSubscriber.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function prePersist(LifecycleEventArgs $args): void
6666
$entity = $args->getObject();
6767

6868
if ($entity instanceof ProductClass) {
69-
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() === null ? '0' : $entity->getPrice01(),
69+
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() ?? '0',
7070
$entity->getProduct(), $entity));
7171
$entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
7272
$entity->getProduct(), $entity));
@@ -83,7 +83,7 @@ public function postLoad(LifecycleEventArgs $args): void
8383
$entity = $args->getObject();
8484

8585
if ($entity instanceof ProductClass) {
86-
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() === null ? '0' : $entity->getPrice01(),
86+
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() ?? '0',
8787
$entity->getProduct(), $entity));
8888
$entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
8989
$entity->getProduct(), $entity));
@@ -100,7 +100,7 @@ public function postPersist(LifecycleEventArgs $args): void
100100
$entity = $args->getObject();
101101

102102
if ($entity instanceof ProductClass) {
103-
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() === null ? '0' : $entity->getPrice01(),
103+
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() ?? '0',
104104
$entity->getProduct(), $entity));
105105
$entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
106106
$entity->getProduct(), $entity));
@@ -117,7 +117,7 @@ public function postUpdate(LifecycleEventArgs $args): void
117117
$entity = $args->getObject();
118118

119119
if ($entity instanceof ProductClass) {
120-
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() === null ? '0' : $entity->getPrice01(),
120+
$entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01() ?? '0',
121121
$entity->getProduct(), $entity));
122122
$entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
123123
$entity->getProduct(), $entity));

src/Eccube/Entity/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public function removeItem(ItemInterface $item): void
362362
#[\Override]
363363
public function getQuantity(): string
364364
{
365-
return (string) $this->getTotalQuantity();
365+
return $this->getTotalQuantity();
366366
}
367367

368368
/**

src/Eccube/Entity/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Category extends AbstractEntity implements \Stringable
3939
#[\Override]
4040
public function __toString(): string
4141
{
42-
return (string) $this->getName();
42+
return $this->getName();
4343
}
4444

4545
/**

src/Eccube/Entity/ClassCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ClassCategory extends AbstractEntity implements \Stringable
3737
#[\Override]
3838
public function __toString(): string
3939
{
40-
return (string) $this->getName();
40+
return $this->getName();
4141
}
4242

4343
/**

src/Eccube/Entity/Master/AbstractMasterEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class AbstractMasterEntity extends \Eccube\Entity\AbstractEntity implem
2828
#[\Override]
2929
public function __toString(): string
3030
{
31-
return (string) $this->getName();
31+
return $this->getName();
3232
}
3333

3434
/**

src/Eccube/Entity/News.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class News extends AbstractEntity implements \Stringable
3939
#[\Override]
4040
public function __toString(): string
4141
{
42-
return (string) $this->getTitle();
42+
return $this->getTitle();
4343
}
4444

4545
/**

src/Eccube/Entity/Order.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ public function getQuantity(): string
19571957
{
19581958
$quantity = '0';
19591959
foreach ($this->getItems() as $item) {
1960-
$quantity = bcadd($quantity, (string) $item->getQuantity());
1960+
$quantity = bcadd($quantity, $item->getQuantity());
19611961
}
19621962

19631963
return $quantity;

0 commit comments

Comments
 (0)