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

feat: add phpstan for static analysis #1223

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions .github/workflows/analyse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Static analysis

on:
push:
pull_request:

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-20.04

# 'push' runs on inner branches, 'pull_request' will run only on outer PRs
if: >
github.event_name == 'push'
|| (github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.full_name != github.repository)

steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and start Docker container
working-directory: install/automated/docker
run: |
docker build -t openvk ../../.. -f openvk.Dockerfile

- name: Run Docker container with PHPStan
working-directory: install/automated/docker
run: |
docker container run --rm \
-v ./chandler.example.yml:/opt/chandler/chandler.yml \
-v ./openvk.example.yml:/opt/chandler/extensions/available/openvk/openvk.yml \
openvk vendor/bin/phpstan analyse --memory-limit 1G
10 changes: 10 additions & 0 deletions chandler_loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace openvk;

$_SERVER["HTTP_ACCEPT_LANGUAGE"] = false;
$bootstrap = require(__DIR__ . "/../../../chandler/Bootstrap.php");
$bootstrap->ignite(true);
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"scripts": {
"fix": "php-cs-fixer fix",
"lint": "php-cs-fixer fix --dry-run --diff --verbose"
"lint": "php-cs-fixer fix --dry-run --diff --verbose",
"analyse": "phpstan analyse --memory-limit 1G"
},
"require": {
"php": "~7.3||~8.1",
Expand All @@ -28,6 +29,7 @@
},
"minimum-stability": "beta",
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.68"
"friendsofphp/php-cs-fixer": "^3.68",
"phpstan/phpstan": "^2.1"
}
}
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions openvkctl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ namespace openvk;

use Symfony\Component\Console\Application;

$_SERVER["HTTP_ACCEPT_LANGUAGE"] = false;
$bootstrap = require(__DIR__ . "/../../../chandler/Bootstrap.php");
$bootstrap->ignite(true);
require(__DIR__ . "/chandler_loader.php");

$application = new Application();
$application->add(new CLI\RebuildImagesCommand());
Expand Down
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
level: 0
paths:
- CLI
- ServiceAPI
- VKAPI
- Web
- bootstrap.php
- openvkctl
- chandler_loader.php

bootstrapFiles:
- chandler_loader.php
- bootstrap.php
Loading