Skip to content

Commit 2c34f72

Browse files
committed
Merge branch 'pt-12044/5.2/introduce-phpstan' into 'master'
PT-12044 - Introduce PHPStan See merge request shopware/5/services/swagpaymentpaypalunified!41
2 parents 269cfdb + 87c2a6b commit 2c34f72

File tree

22 files changed

+456
-15
lines changed

22 files changed

+456
-15
lines changed

.githooks/pre-commit

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PreCommitChecks
3131

3232
$this->runPhpLint($this->getCommittedFileList());
3333
$this->runPhpCsFixer($this->getCommittedFileList());
34+
$this->runPHPStan($this->getCommittedFileList());
3435
$this->runEsLint($this->getCommittedFileList('js'));
3536

3637
if ($this->error) {
@@ -139,6 +140,31 @@ class PreCommitChecks
139140
$this->writeln();
140141
}
141142

143+
private function runPHPStan(array $fileList)
144+
{
145+
$this->writeln('# Checking code with PHPStan');
146+
$this->writeln('> phpstan.phar analyse');
147+
$this->writeln();
148+
149+
if ($fileList === []) {
150+
return;
151+
}
152+
153+
if (!$this->isPHPStanAvailable()) {
154+
$this->writeln('- PHPStan is NOT installed. Please install composer with dev dependencies or use higher Shopware version.', 2);
155+
$this->writeln();
156+
157+
return;
158+
}
159+
160+
exec('./../../../vendor/phpstan/phpstan/phpstan.phar analyse .', $output, $return);
161+
if ($return !== 0) {
162+
$this->error = true;
163+
}
164+
165+
$this->writeln();
166+
}
167+
142168
/**
143169
* @param array $fileList
144170
*/
@@ -171,6 +197,18 @@ class PreCommitChecks
171197
return !(bool) $return;
172198
}
173199

200+
/**
201+
* @return bool
202+
*/
203+
private function isPHPStanAvailable()
204+
{
205+
$output = [];
206+
$return = 0;
207+
exec('command -v ./../../../vendor/phpstan/phpstan/phpstan.phar >/dev/null 2>&1', $output, $return);
208+
209+
return !(bool) $return;
210+
}
211+
174212
/**
175213
* @return bool
176214
*/

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ PHP analyze:
5050
- cp /usr/local/bin/composer composer.phar
5151
- php composer.phar install
5252
- vendor/bin/php-cs-fixer fix --dry-run -v --config=custom/plugins/SwagPaymentPayPalUnified/.php_cs.dist --format=junit | tee php-cs-fixer.xml
53+
- vendor/phpstan/phpstan/phpstan.phar analyse custom/plugins/SwagPaymentPayPalUnified -c custom/plugins/SwagPaymentPayPalUnified/phpstan.neon
5354
artifacts:
5455
reports:
5556
junit: shopware/php-cs-fixer.xml

Bundle/AccountBundle/Service/Validator/AddressValidatorDecorator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Shopware\Components\Api\Exception\ValidationException;
1313
use Shopware\Models\Customer\Address;
1414
use Symfony\Component\Validator\ConstraintViolationInterface;
15+
use Symfony\Component\Validator\ConstraintViolationList;
1516

1617
class AddressValidatorDecorator implements AddressValidatorInterface
1718
{
@@ -54,6 +55,7 @@ public function validate(Address $address)
5455
try {
5556
$this->innerValidator->validate($address);
5657
} catch (ValidationException $exception) {
58+
/** @var ConstraintViolationList $violations */
5759
$violations = $exception->getViolations();
5860

5961
// these values are not always provided by PayPal, but might be required due to the shop settings

Components/Backend/CaptureService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function captureOrder($orderId, $amountToCapture, $currency, $isFinal)
8989
}
9090

9191
/**
92+
* @param string $authorizationId
9293
* @param string $amountToCapture
9394
* @param string $currency
9495
* @param bool $isFinal

Components/Document/InstallmentsDocumentHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(Connection $dbalConnection, OrderCreditInfoService $
3232
}
3333

3434
/**
35-
* @param int $orderNumber
35+
* @param string $orderNumber
3636
*/
3737
public function handleDocument($orderNumber, Document $document)
3838
{

Components/Document/InvoiceDocumentHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(
4848
}
4949

5050
/**
51-
* @param int $orderNumber
51+
* @param string $orderNumber
5252
*/
5353
public function handleDocument($orderNumber, Document $document)
5454
{

Components/Exception/OrderNotFoundException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
class OrderNotFoundException extends \RuntimeException
1212
{
13+
/**
14+
* @param string $parameter
15+
* @param string $value
16+
* @param int $code
17+
*/
1318
public function __construct($parameter, $value, $code = 0, \Throwable $previous = null)
1419
{
1520
$message = sprintf('Could not find order with search parameter "%s" and value "%s"', $parameter, $value);

Components/Services/OrderDataService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function setOrderState($orderNumber, $orderStateId)
8383
{
8484
$builder = $this->dbalConnection->createQueryBuilder();
8585
$builder->update('s_order', 'o')
86-
->set('o.status', $orderStateId)
86+
->set('o.status', (string) $orderStateId)
8787
->where('o.ordernumber = :orderNumber')
8888
->setParameter(':orderNumber', $orderNumber)
8989
->execute();

Components/Services/PaymentBuilderService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PaymentBuilderService implements PaymentBuilderInterface
5454
*/
5555
private $basketData;
5656

57-
/*
57+
/**
5858
* @var array
5959
*/
6060
private $userData;

Components/Services/Plus/PaymentInstructionService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function createInstructions($orderNumber, PaymentInstruction $paymentInst
4949
$model->setBankName($paymentInstruction->getRecipientBanking()->getBankName());
5050
$model->setBic($paymentInstruction->getRecipientBanking()->getBic());
5151
$model->setIban($paymentInstruction->getRecipientBanking()->getIban());
52-
$model->setAmount($paymentInstruction->getAmount()->getValue());
52+
$model->setAmount((string) $paymentInstruction->getAmount()->getValue());
5353
$model->setDueDate($paymentInstruction->getDueDate());
5454
$model->setReference($paymentInstruction->getReferenceNumber());
5555

0 commit comments

Comments
 (0)