Skip to content

Commit

Permalink
[Task]: Setup Phpstan #4 (#4)
Browse files Browse the repository at this point in the history
* Task: Setup PHPStan

* Task: Add phpstan require-dev

* Task: fix handleResponse phpdoc

* Task: add/fix phpdoc params and return

* Apply php-cs-fixer changes

* fix missing null in phpdocblock

Co-authored-by: kingjia90 <kingjia90@users.noreply.github.com>
  • Loading branch information
kingjia90 and kingjia90 authored Dec 12, 2022
1 parent 641d945 commit 444b194
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/ci/files/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_ENV=test
5 changes: 5 additions & 0 deletions .github/ci/scripts/setup-pimcore-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -eu -o xtrace

cp .github/ci/files/.env .
50 changes: 50 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Static Analysis"

on:
pull_request:
branches:
- "[0-9]+.[0-9]+"
- "[0-9]+.x"
push:
branches:
- "[0-9]+.[0-9]+"
- "[0-9]+.x"

jobs:
static-analysis-phpstan:
name: "Static Analysis with PHPStan"
runs-on: "ubuntu-20.04"
strategy:
matrix:
include:
- { php-version: 8.0, database: "mariadb:10.7", pimcore_version: "", dependencies: lowest, experimental: false }
- { php-version: 8.1, database: "mariadb:10.7", pimcore_version: "", dependencies: highest, experimental: false }
steps:
- name: "Checkout code"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Setup Pimcore environment"
run: |
.github/ci/scripts/setup-pimcore-environment.sh
# - name: "Update Pimcore version"
# env:
# PIMCORE_VERSION: "${{ matrix.pimcore_version }}"
# run: |
# if [ ! -z "$PIMCORE_VERSION" ]; then
# composer require --no-update pimcore/pimcore:"${PIMCORE_VERSION}"
# fi

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse ${{ matrix.phpstan_args }} -c phpstan.neon --memory-limit=-1"
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"klarna/checkout": "^3.0.0",
"pimcore/pimcore": "^10.0.0"
},
"require-dev": {
"phpstan/phpstan": "^1.9"
},
"autoload": {
"psr-4": {
"Pimcore\\Bundle\\EcommerceFrameworkBundle\\": "src/"
Expand Down
2 changes: 2 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors:
19 changes: 19 additions & 0 deletions phpstan-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
define('PIMCORE_PROJECT_ROOT', __DIR__);
} elseif (file_exists(__DIR__ . '/../../../vendor/autoload.php')) {
define('PIMCORE_PROJECT_ROOT', __DIR__ . '/../../..');
} elseif (getenv('PIMCORE_PROJECT_ROOT')) {
define('PIMCORE_PROJECT_ROOT', getenv('PIMCORE_PROJECT_ROOT'));
} else {
throw new \Exception('Unknown configuration! Pimcore project root not found, please set env variable PIMCORE_PROJECT_ROOT.');
}

include PIMCORE_PROJECT_ROOT . '/vendor/autoload.php';
\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();

if (!defined('PIMCORE_TEST')) {
define('PIMCORE_TEST', true);
}
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 5
paths:
- src
bootstrapFiles:
- phpstan-bootstrap.php
includes:
- phpstan-baseline.neon
19 changes: 14 additions & 5 deletions src/PaymentManager/Payment/Klarna.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getName()
*
* @param PriceInterface $price
* @param array $config
* @param CartInterface $cart
* @param null|CartInterface $cart
*
* @return string
*
Expand Down Expand Up @@ -157,7 +157,11 @@ public function startPayment(OrderAgentInterface $orderAgent, PriceInterface $pr
}

/**
* @inheritdoc
* Handles response of payment provider and creates payment status object
*
* @param StatusInterface|array $response
*
* @return StatusInterface
*/
public function handleResponse($response)
{
Expand Down Expand Up @@ -204,7 +208,7 @@ public function handleResponse($response)
}

/**
* @inheritdoc
* @return array
*/
public function getAuthorizedData()
{
Expand All @@ -220,7 +224,12 @@ public function setAuthorizedData(array $authorizedData)
}

/**
* @inheritdoc
* @param PriceInterface|null $price
* @param string|null $reference
*
* @return StatusInterface
*
* @throws \Exception
*/
public function executeDebit(PriceInterface $price = null, $reference = null)
{
Expand Down Expand Up @@ -274,7 +283,7 @@ public function executeCredit(PriceInterface $price, $reference, $transactionId)
}

/**
* @param string $uri
* @param string|null $uri
*
* @return \Klarna_Checkout_Order
*/
Expand Down

0 comments on commit 444b194

Please sign in to comment.