-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New static parse method, bugfix and code quality
New feature: - Add static method to create PSR-7 Uri object: Url::parsePsr7(). Bugfix: - Fix error when resolving something to a url with an empty path. Code quality: - Update php cs fixer to ^v3.4. - Add phpstan at level 6. - Add `composer cs-fix` command that automatically fixes code style. - Improve pre-commit hook and add running phpstan.
- Loading branch information
Showing
35 changed files
with
479 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
composer.lock | ||
vendor | ||
.php_cs.cache | ||
.php-cs-fixer.cache | ||
.phpunit.result.cache | ||
data/public_suffix_list.dat | ||
data/uri-schemes.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
$finder = Finder::create() | ||
->in([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/bin']); | ||
$config = new Config(); | ||
|
||
return PhpCsFixer\Config::create() | ||
return $config->setFinder($finder) | ||
->setRules([ | ||
'@PSR2' => true, | ||
'strict_param' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'single_class_element_per_statement' => false, | ||
]) | ||
->setFinder($finder); | ||
->setRiskyAllowed(true) | ||
->setUsingCache(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,80 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
function handleFail($output, $returnCode) { | ||
run('composer test', 'Unit tests'); | ||
run('composer cs', 'PHP Coding Standards Fixer'); | ||
run('composer stan', 'PHPStan'); | ||
exit(0); | ||
|
||
function run(string $command, ?string $descriptiveName = null) | ||
{ | ||
printLine(blue('RUN ' . ($descriptiveName ?? $command) . '...')); | ||
exec($command, $output, $returnCode); | ||
handleFail($output, $returnCode); | ||
showSummary($output); | ||
} | ||
|
||
function handleFail($output, $returnCode) | ||
{ | ||
if ($returnCode !== 0) { | ||
// Show full output | ||
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL; | ||
echo "Aborting commit.." . PHP_EOL; | ||
printLine(red('Failed:')); | ||
printLines($output); | ||
printLine(red('Aborting commit...')); | ||
exit(1); | ||
} | ||
} | ||
|
||
echo "Running tests.. "; | ||
exec('composer test', $output, $returnCode); | ||
handleFail($output, $returnCode); | ||
function showSummary(array $output) | ||
{ | ||
printBlankLine(); | ||
printLine(green('Summary:')); | ||
outputLastNotEmptyLine($output); | ||
printBlankLine(); | ||
} | ||
|
||
echo "Running php-cs-fixer.. "; | ||
exec('composer cs', $output, $returnCode); | ||
handleFail($output, $returnCode); | ||
function outputLastNotEmptyLine(array $output) | ||
{ | ||
while (count($output) > 0) { | ||
$lastLine = array_pop($output); | ||
|
||
// Show summary (last line) | ||
echo array_pop($output) . PHP_EOL; | ||
if (trim($lastLine) !== '') { | ||
printLine($lastLine); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
exit(0); | ||
function printLine(string $string) | ||
{ | ||
echo $string . PHP_EOL; | ||
} | ||
|
||
function printLines(array $lines) | ||
{ | ||
echo implode(PHP_EOL, $lines) . PHP_EOL; | ||
} | ||
|
||
function printBlankLine() | ||
{ | ||
printLine(''); | ||
} | ||
|
||
function red(string $string): string | ||
{ | ||
return color('0;31', $string); | ||
} | ||
|
||
function green(string $string): string | ||
{ | ||
return color('0;32', $string); | ||
} | ||
|
||
function blue(string $string): string | ||
{ | ||
return color('0;34', $string); | ||
} | ||
|
||
function color(string $colorCode, string $string): string | ||
{ | ||
return "\e[" . $colorCode . "m" . $string . "\e[0m"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
parameters: | ||
level: 6 | ||
paths: | ||
- src | ||
- tests | ||
treatPhpDocTypesAsCertain: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Crwlr\Url\Exceptions; | ||
|
||
use Exception; | ||
|
||
class ListStoreException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.