Skip to content

Commit 6840a31

Browse files
committed
PHPStan level 6
1 parent 7b22ba1 commit 6840a31

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PHPFUI\MySQLSlowLog\Parser [![Tests](https://github.com/phpfui/MySQLSlowQueryParser/actions/workflows/tests.yml/badge.svg)](https://github.com/phpfui/MySQLSlowQueryParser/actions?query=workflow%3Atests) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/mysql-slow-log-parser.svg)](https://packagist.org/packages/phpfui/mysql-slow-log-parser)
1+
# PHPFUI\MySQLSlowLog\Parser [![Tests](https://github.com/phpfui/MySQLSlowQueryParser/actions/workflows/tests.yml/badge.svg)](https://github.com/phpfui/MySQLSlowQueryParser/actions?query=workflow%3Atests) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/mysql-slow-log-parser.svg)](https://packagist.org/packages/phpfui/mysql-slow-log-parser) ![](https://img.shields.io/badge/PHPStan-level%206-brightgreen.svg?style=flat)
22

33
PHP Parser for MySQL Slow Query Logs featuring sortable results
44

phpstan.neon.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parameters:
2+
level: 6
3+
errorFormat: raw
4+
editorUrl: '%%file%% %%line%% %%column%%: %%error%%'
5+
paths:
6+
- src
7+
- tests
8+
ignoreErrors:
9+
-
10+
message: '#Access to an undefined property PHPFUI\\MySQLSlowQuery\\Entry::#'
11+
paths:
12+
- tests/*
13+
-
14+
message: '#Access to an undefined property PHPFUI\\MySQLSlowQuery\\Session::#'
15+
paths:
16+
- tests/*
17+
18+

src/PHPFUI/MySQLSlowQuery/BaseObject.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
abstract class BaseObject
66
{
7+
/** @var array<string, mixed> $fields */
78
protected array $fields = [];
89

9-
abstract public function __construct(array $paramters = []);
10+
/** @param array<string, string> $parameters $parameters */
11+
abstract public function __construct(array $parameters = []);
1012

1113
/**
1214
* Allows for $object->field syntax
15+
*
16+
* @return string | array<int, mixed>
1317
*/
1418
public function __get(string $field)
1519
{
@@ -24,6 +28,8 @@ public function __get(string $field)
2428
/**
2529
* Allows for $object->field = $x syntax
2630
*
31+
* @param mixed $value value to set
32+
*
2733
* @return mixed returns $value so you can string together assignments
2834
*/
2935
public function __set(string $field, $value)
@@ -38,6 +44,7 @@ public function __set(string $field, $value)
3844
return $value;
3945
}
4046

47+
/** @return array<string, mixed> */
4148
public function asArray() : array
4249
{
4350
return $this->fields;

src/PHPFUI/MySQLSlowQuery/Entry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class Entry extends \PHPFUI\MySQLSlowQuery\BaseObject
66
{
7+
// @phpstan-ignore-next-line
78
public function __construct(array $parameters = [])
89
{
910
$this->fields = [

src/PHPFUI/MySQLSlowQuery/Parser.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ class Parser
88

99
private const TIME = '# Time: ';
1010

11+
/** @var array<int, \PHPFUI\MySQLSlowQuery\Entry> */
1112
private array $entries = [];
1213

14+
/** @var array<int, string> */
1315
private array $extraLines = [];
1416

1517
private string $fileName = '';
1618

19+
// @phpstan-ignore-next-line
1720
private $handle;
1821

1922
private bool $inSession = true;
2023

24+
/** @var array<int, \PHPFUI\MySQLSlowQuery\Session> */
2125
private array $sessions = [];
2226

2327
private string $sortColumn = 'Query_time';
@@ -39,6 +43,8 @@ public function __construct(string $fileName)
3943
*
4044
* @throws Exception\EmptyLog
4145
* @throws Exception\LogLine
46+
* @return array<int, \PHPFUI\MySQLSlowQuery\Entry>
47+
*
4248
*/
4349
public function getEntries(int $session = -1) : array
4450
{
@@ -53,6 +59,7 @@ public function getEntries(int $session = -1) : array
5359

5460
foreach ($this->entries as $entry)
5561
{
62+
// @phpstan-ignore-next-line
5663
if ($entry->Session == $session)
5764
{
5865
$entries[] = $entry;
@@ -66,10 +73,10 @@ public function getEntries(int $session = -1) : array
6673
}
6774

6875
/**
69-
* Return \PHPFUI\MySQLSlowQuery\Session sessions from file
70-
*
7176
* @throws Exception\EmptyLog
7277
* @throws Exception\LogLine
78+
* @return array<int, \PHPFUI\MySQLSlowQuery\Session> sessions from file
79+
*
7380
*/
7481
public function getSessions() : array
7582
{
@@ -114,7 +121,7 @@ protected function entrySort(\PHPFUI\MySQLSlowQuery\Entry $lhs, \PHPFUI\MySQLSlo
114121
return $lhs->{$column} <=> $rhs->{$column};
115122
}
116123

117-
private function getNextLine()
124+
private function getNextLine() : string
118125
{
119126
if ($this->extraLines)
120127
{
@@ -163,6 +170,7 @@ private function parse() : void
163170

164171
$query = [];
165172

173+
// @phpstan-ignore-next-line
166174
while (\strlen($line = $this->getNextLine()) > 0 && '#' !== $line[0])
167175
{
168176
if (0 === \stripos($line, self::PORT))// found a session
@@ -186,7 +194,9 @@ private function parse() : void
186194
{
187195
$this->pushLine($line);
188196
}
197+
// @phpstan-ignore-next-line
189198
$entry->Query = $query;
199+
// @phpstan-ignore-next-line
190200
$entry->Session = \count($this->sessions) - 1;
191201
$this->entries[] = $entry;
192202
}

src/PHPFUI/MySQLSlowQuery/Session.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class Session extends \PHPFUI\MySQLSlowQuery\BaseObject
66
{
7+
/** @param array<int, string> $sessionData */
78
public function __construct(array $sessionData = [])
89
{
910
$this->fields = [
@@ -12,10 +13,12 @@ public function __construct(array $sessionData = [])
1213
'Transport' => '',
1314
];
1415

16+
// @phpstan-ignore-next-line
1517
$this->Server = \trim(\str_replace('. started with:', '', $sessionData[0] ?? 'unknown'));
1618

1719
if (\strpos($sessionData[1] ?? '', ', '))
1820
{
21+
// @phpstan-ignore-next-line
1922
[$this->Port, $this->Transport] = \explode(', ', \trim($sessionData[1]));
2023
}
2124
}

tests/UnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ public function testInvalidGet() : void
3535
{
3636
$this->expectException(\PHPFUI\MySQLSlowQuery\Exception\Get::class);
3737
$entry = new \PHPFUI\MySQLSlowQuery\Entry();
38+
// @phpstan-ignore-next-line
3839
$entry->fred;
3940
}
4041

4142
public function testInvalidSet() : void
4243
{
4344
$this->expectException(\PHPFUI\MySQLSlowQuery\Exception\Set::class);
4445
$entry = new \PHPFUI\MySQLSlowQuery\Entry();
46+
// @phpstan-ignore-next-line
4547
$entry->fred = 'Ethyl';
4648
}
4749

0 commit comments

Comments
 (0)