Skip to content

Commit

Permalink
PHPStan レベル2の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-gillingham committed Nov 7, 2023
1 parent 8101d50 commit 5b14324
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/Eccube/Controller/Admin/Store/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,8 @@ public function install(Request $request)
if ($form->isSubmitted() && $form->isValid()) {
/** @var \Eccube\Entity\Template $Template */
$Template = $form->getData();

$TemplateExists = $this->templateRepository->findByCode($Template->getCode());

// テンプレートコードの重複チェック.
// テンプレートコードの重複チェック.s
if ($TemplateExists) {
$form['code']->addError(new FormError(trans('admin.store.template.template_code_already_exists')));

Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Controller/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ private function createPaymentMethod(Order $Order, FormInterface $form)
*
* @param PaymentMethodInterface $paymentMethod
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|void
*/
protected function executeApply(PaymentMethodInterface $paymentMethod)
{
Expand Down
8 changes: 6 additions & 2 deletions src/Eccube/Doctrine/Common/CsvDataFixtures/CsvFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;

/**
Expand Down Expand Up @@ -44,6 +45,10 @@ public function __construct(\SplFileObject $file = null)
*/
public function load(ObjectManager $manager)
{
if($manager instanceof EntityManagerInterface === false) {
return;
}

// 日本語windowsの場合はインストール時にエラーとなるので英語のロケールをセット
// ロケールがミスマッチしてSplFileObject::READ_CSVができないのを回避
if ('\\' === DIRECTORY_SEPARATOR) {
Expand All @@ -56,11 +61,10 @@ public function load(ObjectManager $manager)
// ヘッダ行を取得
$headers = $this->file->current();
$this->file->next();

// ファイル名からテーブル名を取得
$table_name = str_replace('.'.$this->file->getExtension(), '', $this->file->getFilename());
$sql = $this->getSql($table_name, $headers);
/** @var Connection $Connection */
/** @var \Doctrine\DBAL\Connection $Connection */
$Connection = $manager->getConnection();
$Connection->beginTransaction();

Expand Down
5 changes: 5 additions & 0 deletions src/Eccube/Entity/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public function getPointRate();
* @return $this
*/
public function setPrice($price);

/**
* @return mixed
*/
public function getPriceIncTax();
}
6 changes: 3 additions & 3 deletions src/Eccube/Entity/PointTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
trait PointTrait
{
/**
* @var string
* @var string|int|float
*
* @ORM\Column(name="add_point", type="decimal", precision=12, scale=0, options={"unsigned":true,"default":0})
*/
private $add_point = '0';

/**
* @var string
* @var string|int|float
*
* @ORM\Column(name="use_point", type="decimal", precision=12, scale=0, options={"unsigned":true,"default":0})
*/
Expand Down Expand Up @@ -72,7 +72,7 @@ public function setUsePoint($usePoint)
/**
* Get usePoint
*
* @return string
* @return string|int|float
*/
public function getUsePoint()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/EventListener/LoginHistoryListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function onAuthenticationFailure(LoginFailureEvent $event)
$Member = null;
$userName = null;
$passport = $event->getPassport();
if ($passport->hasBadge(UserBadge::class)) {
if ($passport->hasBadge(UserBadge::class) && $passport->getBadge(UserBadge::class) instanceof UserBadge) {
$userName = $passport->getBadge(UserBadge::class)
->getUserIdentifier();
$Member = $this->memberRepository->findOneBy(['login_id' => $userName]);
Expand Down
10 changes: 8 additions & 2 deletions src/Eccube/EventListener/TransactionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public function onKernelException(ExceptionEvent $event)
return;
}

if ($this->em->getConnection()->getNativeConnection()->inTransaction()) {
/** @var \PDO $nativeConnection */
$nativeConnection = $this->em->getConnection()->getNativeConnection();
if ($nativeConnection->inTransaction()) {
if ($this->em->getConnection()->isRollbackOnly()) {
$this->em->rollback();
}
Expand All @@ -129,7 +131,11 @@ public function onKernelTerminate(TerminateEvent $event)

return;
}
if ($this->em->getConnection()->getNativeConnection()->inTransaction()) {

/** @var \PDO $nativeConnection */
$nativeConnection = $this->em->getConnection()->getNativeConnection();

if ($nativeConnection->inTransaction()) {
if ($this->em->getConnection()->isRollbackOnly()) {
$this->em->rollback();
log_debug('Rollback executed.');
Expand Down
3 changes: 3 additions & 0 deletions src/Eccube/Repository/TemplateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*
* @method array<int, Template> findByCode(string $code)
* @method Template|null findOneByCode(string $code)
*/
class TemplateRepository extends AbstractRepository
{
Expand Down
7 changes: 4 additions & 3 deletions src/Eccube/Resource/functions/trans.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ function trans($id, array $parameters = [], $domain = null, $locale = null)
return $Translator->trans($id, $parameters, $domain, $locale);
}

/**
* @deprecated transを使用してください。
*/
function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
{
$Translator = TranslatorFacade::create();

return $Translator->transChoice($id, $number, $parameters, $domain, $locale);
return trans($id, $parameters, $domain, $locale);
}
18 changes: 14 additions & 4 deletions src/Eccube/Service/PluginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,16 @@ public function postInstall($config, $source)
$this->entityManager->persist($Plugin);
$this->entityManager->flush();

if ($this->entityManager->getConnection()->getNativeConnection()->inTransaction()) {
/** @var \PDO $nativeConnection */
$nativeConnection = $this->entityManager->getConnection()->getNativeConnection();

if ($nativeConnection->inTransaction()) {
$this->entityManager->getConnection()->commit();
}
} catch (\Exception $e) {
if ($this->entityManager->getConnection()->getNativeConnection()->inTransaction()) {
/** @var \PDO $nativeConnection */
$nativeConnection = $this->entityManager->getConnection()->getNativeConnection();
if ($nativeConnection->inTransaction()) {
if ($this->entityManager->getConnection()->isRollbackOnly()) {
$this->entityManager->getConnection()->rollback();
}
Expand Down Expand Up @@ -783,11 +788,16 @@ public function updatePlugin(Plugin $plugin, $meta)
}
$this->copyAssets($plugin->getCode());
$em->flush();
if ($em->getConnection()->getNativeConnection()->inTransaction()) {

/** @var \PDO $nativeConnection */
$nativeConnection = $em->getConnection()->getNativeConnection();
if ($nativeConnection->inTransaction()) {
$em->getConnection()->commit();
}
} catch (\Exception $e) {
if ($em->getConnection()->getNativeConnection()->inTransaction()) {
/** @var \PDO $nativeConnection */
$nativeConnection = $em->getConnection()->getNativeConnection();
if ($nativeConnection->inTransaction()) {
if ($em->getConnection()->isRollbackOnly()) {
$em->getConnection()->rollback();
}
Expand Down
25 changes: 19 additions & 6 deletions src/Eccube/Service/SchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Eccube\Doctrine\ORM\Mapping\Driver\NopAnnotationDriver;
use Eccube\Doctrine\ORM\Mapping\Driver\ReloadSafeAnnotationDriver;
use Eccube\Util\StringUtil;
use Doctrine\DBAL;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver;

class SchemaService
{
Expand Down Expand Up @@ -68,8 +71,15 @@ public function executeCallback(callable $callback, $generatedFiles, $proxiesDir
}

try {
$chain = $this->entityManager->getConfiguration()->getMetadataDriverImpl()->getDriver();
$drivers = $chain->getDrivers();
/** @var MappingDriver $mappingDriver */
$mappingDriver = $this->entityManager->getConfiguration()->getMetadataDriverImpl();
/** @var MappingDriverChain $driverChain */
$driverChain = $mappingDriver->getDriver();
$drivers = $driverChain->getDrivers();
/**
* @var string $namespace
* @var ReloadSafeAnnotationDriver $oldDriver
*/
foreach ($drivers as $namespace => $oldDriver) {
if ('Eccube\Entity' === $namespace || preg_match('/^Plugin\\\\.*\\\\Entity$/', $namespace)) {
// Setup to AnnotationDriver
Expand All @@ -82,13 +92,13 @@ public function executeCallback(callable $callback, $generatedFiles, $proxiesDir
$newDriver->setTraitProxiesDirectory($proxiesDirectory);
$newDriver->setNewProxyFiles($generatedFiles);
$newDriver->setOutputDir($outputDir);
$chain->addDriver($newDriver, $namespace);
$driverChain->addDriver($newDriver, $namespace);
}

if ($this->pluginContext->isUninstall()) {
foreach ($this->pluginContext->getExtraEntityNamespaces() as $extraEntityNamespace) {
if ($extraEntityNamespace === $namespace) {
$chain->addDriver(new NopAnnotationDriver(new AnnotationReader()), $namespace);
$driverChain->addDriver(new NopAnnotationDriver(new AnnotationReader()), $namespace);
}
}
}
Expand Down Expand Up @@ -134,8 +144,11 @@ public function updateSchema($generatedFiles, $proxiesDirectory, $saveMode = fal
*/
public function dropTable($targetNamespace)
{
$chain = $this->entityManager->getConfiguration()->getMetadataDriverImpl()->getDriver();
$drivers = $chain->getDrivers();
/** @var MappingDriver $mappingDriver */
$mappingDriver = $this->entityManager->getConfiguration()->getMetadataDriverImpl();
/** @var MappingDriverChain $driverChain */
$driverChain = $mappingDriver->getDriver();
$drivers = $driverChain->getDrivers();

$dropMetas = [];
foreach ($drivers as $namespace => $driver) {
Expand Down

0 comments on commit 5b14324

Please sign in to comment.