Skip to content

Commit 3bee794

Browse files
authored
Merge pull request #72 from minkphp/add_phpstan
Add static analysis with phpstan
2 parents 8097ad7 + a0a0911 commit 3bee794

40 files changed

Lines changed: 156 additions & 46 deletions

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
tab_width = 4
10+
trim_trailing_whitespace = true
11+
12+
[.github/workflows/*.yml]
13+
indent_size = 2

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.github export-ignore
2+
/.editorconfig export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/phpstan*.neon export-ignore

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
check_composer:
14+
name: Check composer.json
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: shivammathur/setup-php@v2
19+
with:
20+
coverage: none
21+
php-version: '8.2'
22+
- run: composer validate --strict --no-check-lock
23+
24+
static_analysis:
25+
name: Static analysis
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
- uses: shivammathur/setup-php@v2
30+
with:
31+
coverage: none
32+
php-version: '8.2'
33+
- name: Install dependencies
34+
run: composer update --ansi --no-progress --prefer-dist --no-interaction
35+
- run: vendor/bin/phpstan analyze

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"yoast/phpunit-polyfills": "^1.0"
2828
},
2929
"require-dev": {
30+
"phpstan/phpstan": "^1.10",
31+
"phpstan/phpstan-phpunit": "^1.3",
32+
"phpstan/phpstan-symfony": "^1.3",
3033
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0"
3134
},
3235
"conflict": {

http-kernel-fixtures/advanced_form_post.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<pre>
99
<?php
1010
error_reporting(0);
11+
/** @var \Symfony\Component\HttpFoundation\Request $request */
1112

1213
$POST = $request->request->all();
1314
$FILES = $request->files->all();
@@ -19,7 +20,7 @@
1920
echo html_escape_value(mink_dump($POST)) . "\n";
2021
if (isset($FILES['about']) && file_exists($FILES['about']->getPathname())) {
2122
echo html_escape_value($FILES['about']->getClientOriginalName()) . "\n";
22-
echo html_escape_value(file_get_contents($FILES['about']->getPathname()));
23+
echo html_escape_value(file_get_contents($FILES['about']->getPathname()) ?: '');
2324
} else {
2425
echo "no file";
2526
}

http-kernel-fixtures/basic_auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
/** @var \Symfony\Component\HttpFoundation\Request $request */
23
$SERVER = $request->server->all();
34

45
$username = isset($SERVER['PHP_AUTH_USER']) ? $SERVER['PHP_AUTH_USER'] : false;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<?php ?>
1+
<?php /** @var \Symfony\Component\HttpFoundation\Request $request */ ?>
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
44
<head>
55
<title>Basic Form Saving</title>
66
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
77
</head>
88
<body>
9-
<h1>Anket for <?php echo html_escape_value($request->request->get('first_name')) ?></h1>
9+
<h1>Anket for <?php echo html_escape_value((string) $request->request->get('first_name')) ?></h1>
1010

11-
<span id="first">Firstname: <?php echo html_escape_value($request->request->get('first_name')) ?></span>
12-
<span id="last">Lastname: <?php echo html_escape_value($request->request->get('last_name')) ?></span>
11+
<span id="first">Firstname: <?php echo html_escape_value((string) $request->request->get('first_name')) ?></span>
12+
<span id="last">Lastname: <?php echo html_escape_value((string) $request->request->get('last_name')) ?></span>
1313
</body>
1414
</html>

http-kernel-fixtures/basic_get_form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
<div id="serach">
1111
<?php
12+
/** @var \Symfony\Component\HttpFoundation\Request $request */
1213
$GET = $request->query->all();
13-
echo isset($GET['q']) && $GET['q'] ? html_escape_value($GET['q']) : 'No search query'
14+
echo isset($GET['q']) && $GET['q'] && \is_string($GET['q']) ? html_escape_value($GET['q']) : 'No search query'
1415
?>
1516
</div>
1617

http-kernel-fixtures/cookie_page1.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
/** @var \Symfony\Component\HttpFoundation\Request $request */
23
$resp = new Symfony\Component\HttpFoundation\Response();
34
$cook = Symfony\Component\HttpFoundation\Cookie::create('srvr_cookie', 'srv_var_is_set', 0, '/');
45
$resp->headers->setCookie($cook);

http-kernel-fixtures/cookie_page2.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</head>
99
<body>
1010
Previous cookie: <?php
11+
/** @var \Symfony\Component\HttpFoundation\Request $request */
1112
echo $request->cookies->has('srvr_cookie') ? html_escape_value($request->cookies->get('srvr_cookie')) : 'NO';
1213
?>
1314
</body>

0 commit comments

Comments
 (0)