Skip to content

Commit aa03f3a

Browse files
authored
Merge pull request #95 from mantas-done/stan
Remove all static method calls from Subtitles.php Add phpstan for static analysis
2 parents b1b9ff5 + e82df61 commit aa03f3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2391
-680
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
php-version:
18-
- "7.4"
19-
- "8.0"
20-
- "8.1"
21-
- "8.2"
2218
- "8.3"
2319
- "8.4"
2420
steps:
@@ -36,3 +32,6 @@ jobs:
3632

3733
- name: Run tests
3834
run: vendor/bin/phpunit tests
35+
36+
- name: Run tests
37+
run: vendor/bin/phpstan analyse

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ php subtitles.phar input.srt output.vtt
3737
```
3838
subtitles.phar file can be found here - https://github.com/mantas-done/subtitles/releases
3939

40-
## Installation (supports PHP 7.4...8.4)
40+
## Installation (supports PHP 8.3...8.4)
4141
```
4242
composer require mantas-done/subtitles
4343
```
@@ -48,14 +48,14 @@ Convert .srt file to .vtt:
4848
// add namespace
4949
use \Done\Subtitles\Subtitles;
5050

51-
Subtitles::convert('subtitles.srt', 'subtitles.vtt');
51+
(new Subtitles())->convert('subtitles.srt', 'subtitles.vtt');
5252
```
5353

5454
```php
5555
// if no input format is specified, library will determine file format by its content
5656
// if third parameter is specified, library will convert the file to specified format.
5757
// list of formats are in Subtitle::$formats, they are: ass, dfxp, sbv, srt, stl, sub, ttml, txt_quicktime, vtt
58-
Subtitles::convert('subtitles1', 'subtitles2', ['output_format' => 'vtt']);
58+
(new Subtitles())->convert('subtitles1', 'subtitles2', ['output_format' => 'vtt']);
5959
```
6060

6161
Manually create file
@@ -67,7 +67,7 @@ $subtitles->save('subtitles.vtt');
6767

6868
Load subtitles from existing file
6969
```php
70-
$subtitles = Subtitles::loadFromFile('subtitles.srt');
70+
$subtitles = (new Subtitles())->loadFromFile('subtitles.srt');
7171
```
7272

7373
Load subtitles from string
@@ -78,7 +78,7 @@ $string = "
7878
Senator, we're making our final approach
7979
";
8080

81-
$subtitles = Subtitles::loadFromString($string);
81+
$subtitles = (new Subtitles())->loadFromString($string);
8282
```
8383

8484
Save subtitles to file
@@ -139,19 +139,20 @@ $subtitles->shiftTimeGradually(2, 0, 3600);
139139
## Exceptions ##
140140

141141
Library will throw UserException, it's message can be shown to the user.
142+
142143
```php
143144
try {
144145
(new \Done\Subtitles\Subtitles())->add(0, 1, 'very long text... aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')->content('scc');
145-
} catch (\Done\Subtitles\Code\UserException $e) {
146+
} catch (\Done\Subtitles\Code\Exceptions\UserException $e) {
146147
echo $e->getMessage(); // SCC file can't have more than 4 lines of text each 32 characters long. This text is too long: <text from user file that triggered this error>
147148
}
148149
```
149150
By default, library tries to detect different file errors that can be shown to the user, so he would be able to fix them.
150151
If you want to relax the rules and allow the library to convert even somewhat invalid files, use ['strict' => false]
151152
```php
152-
Subtitles::convert($input, $output, ['strict' => false]);
153-
Subtitles::loadFromString($string, ['strict' => false]);
154-
Subtitles::loadFromFile($input, ['strict' => false]);
153+
(new Subtitles())->convert($input, $output, ['strict' => false]);
154+
(new Subtitles())->loadFromString($string, ['strict' => false]);
155+
(new Subtitles())->loadFromFile($input, ['strict' => false]);
155156
```
156157

157158
## How to add new subtitle format?
@@ -173,7 +174,7 @@ And this is example of [.srt file](https://github.com/mantas783/subtitle-convert
173174
## Registering your converter
174175

175176
```php
176-
Subtitles::registerConverter(FakeDocxConverter::class, 'docx_fake', 'docx', 'Fake docx converter');
177+
(new Subtitles())->registerConverter(FakeDocxConverter::class, 'docx_fake', 'docx', 'Fake docx converter');
177178
```
178179

179180
You can add a new converter or replace the existing one if the format name is the same (the second parameter).
@@ -216,6 +217,7 @@ Array
216217

217218
```
218219
php vendor/bin/phpunit
220+
php vendor/bin/phpstan analyse --memory-limit 4G
219221
```
220222

221223
## Contribution

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
}
1717
},
1818
"require": {
19-
"php": ">=7.4"
19+
"php": ">=8.3"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^8.0"
22+
"phpunit/phpunit": "^12.0",
23+
"phpstan/phpstan": "2.0",
24+
"phpstan/phpstan-strict-rules": "2.0"
2325
}
2426
}

0 commit comments

Comments
 (0)