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

Added PHPStan to verify code samples #2370

Merged
merged 57 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
17a93db
Applied CI review suggestion
mnocon Jul 2, 2024
1ee92a6
Added basic PHPStan config
mnocon Apr 24, 2024
13aff01
Added PHPStan for ActivityLog examples
mnocon Apr 24, 2024
ff41a4d
Added CI
mnocon Apr 24, 2024
c87307d
[TMP] Added invalid code on purpose
mnocon Apr 24, 2024
0783bfe
Fixed auth issues
mnocon Apr 24, 2024
a3f8521
Fixed CS job
mnocon Apr 24, 2024
20bc7f5
PHP CS Fixes
mnocon Apr 24, 2024
64d490d
Rerun
mnocon Apr 24, 2024
4ea50f8
Simplified namespaces
mnocon Apr 24, 2024
dd974af
[TMP] Use the old namespace
mnocon Apr 25, 2024
4f3e5bb
Generated baseline
mnocon May 8, 2024
cc1dbec
Reduced baseline
mnocon May 9, 2024
8cfcd6a
Finished reviewing baseline
mnocon May 9, 2024
51fb2e4
PHP CS Fixes
mnocon May 9, 2024
fb52915
Rerun
mnocon May 9, 2024
a39859e
Removed autoloading
mnocon May 9, 2024
1aeab11
[TMP] Break
mnocon May 9, 2024
c306a61
Adjusted lines
mnocon Jul 2, 2024
46bd6e5
Apply suggestions from code review
mnocon Jul 3, 2024
43349f5
Added space separation
mnocon Jul 3, 2024
35ef89b
Line offset fixes (#2430)
adriendupuis Jul 15, 2024
cc8a8b5
Added basic PHPStan config
mnocon Apr 24, 2024
2d26319
Added PHPStan for ActivityLog examples
mnocon Apr 24, 2024
8fe86b1
Added CI
mnocon Apr 24, 2024
888bdc2
[TMP] Added invalid code on purpose
mnocon Apr 24, 2024
a6f5afe
Fixed auth issues
mnocon Apr 24, 2024
55152a6
Fixed CS job
mnocon Apr 24, 2024
c56e277
PHP CS Fixes
mnocon Apr 24, 2024
73a1450
Rerun
mnocon Apr 24, 2024
ee9c888
Simplified namespaces
mnocon Apr 24, 2024
aee693e
[TMP] Use the old namespace
mnocon Apr 25, 2024
701d924
Generated baseline
mnocon May 8, 2024
2e272b8
Reduced baseline
mnocon May 9, 2024
73ec727
Finished reviewing baseline
mnocon May 9, 2024
ec31d2e
PHP CS Fixes
mnocon May 9, 2024
cb8b1e0
Rerun
mnocon May 9, 2024
3b42e64
Removed autoloading
mnocon May 9, 2024
ac2cfbb
[TMP] Break
mnocon May 9, 2024
2df97b6
Adjusted lines
mnocon Jul 2, 2024
ef77364
Applied CI review suggestion
mnocon Jul 2, 2024
e1e2d91
Apply suggestions from code review
mnocon Jul 3, 2024
9688359
Added space separation
mnocon Jul 3, 2024
8026320
Revert "[TMP] Break"
mnocon Jul 15, 2024
66ea736
Bumped CS-Fixer version
mnocon Jul 15, 2024
4880a27
Fixed CS
mnocon Jul 16, 2024
9f7cc86
Removed redundant doc block from WebinarEventTitleFulltextFieldMapper
mnocon Jul 16, 2024
0ae2840
Added readme mention
mnocon Jul 16, 2024
8aefb6f
Added empty line to cart_api
mnocon Jul 16, 2024
337219c
Removed CS-fixer dependencies
mnocon Jul 16, 2024
182e548
Improved cart_api
mnocon Jul 16, 2024
bc4a920
Update code_samples/recent_activity/src/Command/MonitorRecentContentC…
mnocon Jul 16, 2024
eddb70f
Merge commit '35ef89be785c312f35db3d731840187a2bedda67' into add-phpstan
mnocon Jul 16, 2024
d210b1b
Merge remote-tracking branch 'origin/master' into add-phpstan
mnocon Jul 16, 2024
ae980b4
PHP CS Fixes
mnocon Jul 16, 2024
c8462ed
Removed TMP changes
mnocon Jul 16, 2024
ad3656d
Merge remote-tracking branch 'origin/add-phpstan' into add-phpstan
mnocon Jul 16, 2024
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
110 changes: 73 additions & 37 deletions .github/workflows/build.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general rule of thumb, try to separate each step in jobs with one empty line. This makes it easier for version control to pick up which sections of the jobs changed.

This is true for all YAML files. We do the same for service declarations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for the suggestion!

Original file line number Diff line number Diff line change
@@ -1,62 +1,98 @@
name: 'Build & test documentation'
name: "Build & test documentation"

on:
push:
branches:
- master
- '[0-9]+.[0-9]+'
- "[0-9]+.[0-9]+"
pull_request: ~

jobs:
build:
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install php-cs-fixer
run: composer require friendsofphp/php-cs-fixer --dev
- name: Run PHP CS Fixer
run: ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: PHP CS Fixes
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run build
run: |
mkdocs build --strict
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- uses: "ramsey/composer-install@v3"
with:
working-directory: "tools/php-cs-fixer"
dependency-versions: highest
- name: Run PHP CS Fixer
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: PHP CS Fixes
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run build
run: |
mkdocs build --strict

vale-check:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- uses: actions/checkout@v3
- name: Get Vale.sh configs
env:
TOKEN: ${{ secrets.EZROBOT_PAT }}
run: |
curl -H "Authorization: token $TOKEN" -L https://github.com/ibexa/vale-styles/archive/refs/heads/main.zip -o vale.zip
unzip vale.zip
rm vale.zip
mv vale-styles-main/* vale-styles-main/.vale.ini .
- name: Run Vale.sh
uses: errata-ai/vale-action@reviewdog
with:
- uses: actions/checkout@v4
- name: Get Vale.sh configs
env:
TOKEN: ${{ secrets.EZROBOT_PAT }}
run: |
curl -H "Authorization: token $TOKEN" -L https://github.com/ibexa/vale-styles/archive/refs/heads/main.zip -o vale.zip
unzip vale.zip
rm vale.zip
mv vale-styles-main/* vale-styles-main/.vale.ini .
- name: Run Vale.sh
uses: errata-ai/vale-action@reviewdog
with:
reporter: github-check
filter_mode: added

code-samples:
name: Validate code samples
runs-on: "ubuntu-22.04"
strategy:
matrix:
php:
- "8.3"
steps:
- uses: actions/checkout@v4

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: "pdo_sqlite, gd"
tools: cs2pr

- name: Add composer keys for private packagist
run: |
composer config http-basic.updates.ibexa.co $SATIS_NETWORK_KEY $SATIS_NETWORK_TOKEN
composer config github-oauth.github.com $TRAVIS_GITHUB_TOKEN
env:
SATIS_NETWORK_KEY: ${{ secrets.SATIS_NETWORK_KEY }}
SATIS_NETWORK_TOKEN: ${{ secrets.SATIS_NETWORK_TOKEN }}
TRAVIS_GITHUB_TOKEN: ${{ secrets.TRAVIS_GITHUB_TOKEN }}

- uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- name: Run PHPStan analysis
run: composer phpstan
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/*
**/.idea/
.php-cs-fixer.cache
composer.lock
tools/php-cs-fixer/vendor
22 changes: 19 additions & 3 deletions code_samples/api/commerce/src/Command/CartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace App\Command;

use Ibexa\Contracts\Cart\CartResolverInterface;
use Ibexa\Contracts\Cart\CartServiceInterface;
use Ibexa\Contracts\Cart\Value\CartCreateStruct;
use Ibexa\Contracts\Cart\Value\CartMetadataUpdateStruct;
use Ibexa\Contracts\Cart\Value\CartQuery;
use Ibexa\Contracts\Cart\Value\EntryAddStruct;
use Ibexa\Contracts\Cart\Value\EntryUpdateStruct;
use Ibexa\Contracts\Checkout\Reorder\ReorderService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\OrderManagement\OrderServiceInterface;
use Ibexa\Contracts\ProductCatalog\CurrencyServiceInterface;
use Ibexa\Contracts\ProductCatalog\ProductServiceInterface;
use Ibexa\Core\Repository\Permission\PermissionResolver;
Expand All @@ -30,18 +33,30 @@ final class CartCommand extends Command

private ProductServiceInterface $productService;

private OrderServiceInterface $orderService;

private ReorderService $reorderService;

private CartResolverInterface $cartResolver;

public function __construct(
PermissionResolver $permissionResolver,
UserService $userService,
CartServiceInterface $cartService,
CurrencyServiceInterface $currencyService,
ProductServiceInterface $productService
ProductServiceInterface $productService,
OrderServiceInterface $orderService,
ReorderService $reorderService,
CartResolverInterface $cartResolver
) {
$this->cartService = $cartService;
$this->permissionResolver = $permissionResolver;
$this->userService = $userService;
$this->currencyService = $currencyService;
$this->productService = $productService;
$this->orderService = $orderService;
$this->reorderService = $reorderService;
$this->cartResolver = $cartResolver;

parent::__construct('doc:cart');
}
Expand Down Expand Up @@ -134,9 +149,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// Delete a cart permanently
$this->cartService->deleteCart($cart);

return self::SUCCESS;

// Get the order with items that should be reordered
$orderIdentifier = '2e897b31-0d7a-46d3-ba45-4eb65fe02790';
$order = $this->orderService->getOrderByIdentifier($orderIdentifier);

// Get the cart to merge
Expand All @@ -148,5 +162,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Merge the carts into the target cart and delete the merged carts
$reorderCart = $this->cartService->mergeCarts($reorderCart, true, $existingCart);

return self::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion code_samples/api/commerce/src/Command/OrderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$orderIdentifier = '2e897b31-0d7a-46d3-ba45-4eb65fe02790';
$order = $this->orderService->getOrderByIdentifier($orderIdentifier);

$output->writeln(sprintf('Order has status %s', $orderIdentifier, $order->getStatus()));
$output->writeln(sprintf('Order %s has status %s', $orderIdentifier, $order->getStatus()));

// Get order by id
$orderId = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ibexa\Bundle\Core\Controller;
use Ibexa\Contracts\Cart\CartServiceInterface;
use Ibexa\Contracts\Checkout\CheckoutServiceInterface;
use Symfony\Component\HttpFoundation\Response;

class CustomCheckoutController extends Controller
{
Expand All @@ -20,7 +21,7 @@ public function __construct(CartServiceInterface $cartService, CheckoutServiceIn
$this->checkoutService = $checkoutService;
}

public function showContentAction()
public function showContentAction(): Response
{
// Get checkout for a specific cart
$cart = $this->cartService->getCart('d7424b64-7dc1-474c-82c8-1700f860d55e');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class MyCustomTypeGraphQLCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasParameter('ibexa.graphql.schema.content.mapping.field_definition_type')) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use Ibexa\Contracts\ProductCatalog\Values\Price\Create\Struct\ProductPriceCreateStruct;
use Ibexa\Contracts\ProductCatalog\Values\Price\PriceContext;
use Ibexa\Contracts\ProductCatalog\Values\Price\PriceQuery;
use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\Currency;
use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\Currency as CurrencyCriterion;
use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\CustomerGroup;
use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\LogicalOr;
use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\Product;
use Money;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -90,23 +91,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln('Created new price in currency ' . $newCurrencyCode);

$prices = $this->productPriceService->findPricesByProductCode($productCode);
$prices = $this->productPriceService->findPricesByProductCode($productCode)->getPrices();

$output->writeln('All prices for ' . $product->getName() . ':');
foreach ($prices as $price) {
$output->writeln($price);
$output->writeln((string) $price);
}

$priceCriteria = [
new Currency('USD'),
new CurrencyCriterion($this->currencyService->getCurrencyByCode('USD')),
new CustomerGroup('customer_group_1'),
new Product('ergo_desk'),
];

$priceQuery = new PriceQuery(new LogicalOr(...$priceCriteria));
$prices = $this->priceService->findPrices($priceQuery);
$prices = $this->productPriceService->findPrices($priceQuery);

$output->writeln(sprintf('Found %d prices with provided criteria', count($prices)));
$output->writeln(sprintf('Found %d prices with provided criteria', $prices->getTotalCount()));

$context = new PriceContext($currency);
$price = $this->priceResolver->resolvePrice($product, $context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$vatCategory = $this->vatService->getVatCategoryByIdentifier($region, 'reduced');

$output->writeln($vatCategory->getVatValue());
$output->writeln((string) $vatCategory->getVatValue());

return self::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function __construct(LanguageService $languageService, UserService $userS
parent::__construct('doc:add_language');
}

protected function configure()
protected function configure(): void
{
$this->setDescription('Lists available languages and add Polish.');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(ContentService $contentService, LocationService $loc
parent::__construct('doc:add_location');
}

protected function configure()
protected function configure(): void
{
$this
->setDescription('Add a Location to content item and hides it.')
Expand All @@ -40,7 +40,7 @@ protected function configure()
]);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(BookmarkService $bookmarkService, LocationService $l
parent::__construct('doc:bookmark');
}

protected function configure()
protected function configure(): void
{
$this
->setDefinition([
Expand All @@ -32,7 +32,7 @@ protected function configure()
->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete the created bookmark?', null);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$locationId = $input->getArgument('locationId');
$location = $this->locationService->loadLocation($locationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(LocationService $locationService)
parent::__construct('doc:browse_locations');
}

protected function configure()
protected function configure(): void
{
$this
->setDescription('Lists all descendants of the Location')
Expand All @@ -28,7 +28,7 @@ protected function configure()
]);
}

private function browseLocation(Location $location, OutputInterface $output, $depth = 0)
private function browseLocation(Location $location, OutputInterface $output, int $depth = 0): void
{
$output->writeln($location->contentInfo->name);

Expand All @@ -38,7 +38,7 @@ private function browseLocation(Location $location, OutputInterface $output, $de
}
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$locationId = $input->getArgument('locationId');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(ContentService $contentService, ContentTypeService $
parent::__construct('doc:create_content');
}

protected function configure()
protected function configure(): void
{
$this
->setDefinition([
Expand All @@ -46,7 +46,7 @@ protected function configure()
->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the content item?');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
Expand Down
Loading
Loading