Skip to content

Commit

Permalink
Merge branch 'repository-cleanup-from-base' into 'master'
Browse files Browse the repository at this point in the history
Repository cleanup from base

See merge request tjvb/githash!10
  • Loading branch information
tvbeek committed Aug 15, 2024
2 parents 1b9d0a8 + 6bdea89 commit 9e87481
Show file tree
Hide file tree
Showing 66 changed files with 4,474 additions and 42 deletions.
37 changes: 33 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,52 @@ lint:
- find src/ -type f -name '*.php' -exec php -l {} \; | (! grep -v "No syntax errors detected" )
dependencies: []

phpcs:
phpmd:
stage: check
script:
- vendor/bin/phpcs
- composer phpmd
dependencies:
- prepare_cache
needs:
- prepare_cache

phpmd:
code-style:
stage: check
script:
- composer cs
dependencies:
- prepare_cache
needs:
- prepare_cache

# We check the content with vale
vale:
image:
name: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/jdkato/vale
entrypoint: [""]
stage: check
script:
- vendor/bin/phpmd src/ text phpmd.xml.dist
- /bin/vale --config=tools/vale/.vale.ini docs README.md
needs: []
dependencies: []


infection:
stage: test
image: registry.gitlab.com/tjvb/phpimages:php83
script:
- composer update
- composer infection
dependencies:
- prepare_cache
needs:
- prepare_cache
artifacts:
paths:
- build/infection/
reports:
codequality: build/infection/code-climate-gitlab.json
when: always

test_lowest:
stage: test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you use Laravel you can use [tjvb/laravel-githash](https://gitlab.com/tjvb/la
We (try to) document all the changes in [CHANGELOG](CHANGELOG.md) so read it for more information.

## Contributing
You are very welcome to contribute, read about it in [CONTRIBUTING](CONTRIBUTING.md)
You are welcome to contribute, read about it in [CONTRIBUTING](CONTRIBUTING.md)

## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"phpmd/phpmd": "^2.10",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6",
"slevomat/coding-standard": "^8.14",
"squizlabs/php_codesniffer": "^3.7",
"symplify/easy-coding-standard": "^12.0",
"symfony/process": "^5.3"
},
"suggest": {
Expand All @@ -61,7 +63,8 @@
},
"config": {
"allow-plugins": {
"infection/extension-installer": true
"infection/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
Expand All @@ -78,8 +81,8 @@
"@infection"
],
"check-all": "@check",
"cs": "vendor/bin/phpcs",
"cs-fix": "vendor/bin/phpcbf",
"cs": "vendor/bin/ecs",
"cs-fix": "vendor/bin/ecs --fix",
"codestyle": "@cs",
"format": "@cs-fix",
"infection": "vendor/bin/infection",
Expand Down
92 changes: 92 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

use PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\ArrayIndentSniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterCastSniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PhpCsFixer\Fixer\ClassNotation\FinalClassFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitConstructFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
use SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff;
use SlevomatCodingStandard\Sniffs\Classes\ClassStructureSniff;
use SlevomatCodingStandard\Sniffs\Classes\MethodSpacingSniff;
use SlevomatCodingStandard\Sniffs\Commenting\EmptyCommentSniff;
use SlevomatCodingStandard\Sniffs\Functions\StaticClosureSniff;
use SlevomatCodingStandard\Sniffs\Functions\StrictCallSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff;
use SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\UselessAliasSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff;
use SlevomatCodingStandard\Sniffs\Variables\DisallowSuperGlobalVariableSniff;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])

->withPreparedSets(
psr12: true,
cleanCode: true,
)
->withSkip([
FinalClassFixer::class => [
__DIR__ . '/tests/TestCase.php',
__DIR__ . '/src/Exceptions/GitHashException.php',
],
])
->withConfiguredRule(UnusedUsesSniff::class, [
'searchAnnotations' => true,
])
->withConfiguredRule(ForbiddenFunctionsSniff::class, [
'forbiddenFunctions' => [
'sizeof' => 'count', //keep the default option
'delete' => 'unset', //keep the default option
'dump' => null, //debug statement
'dd' => null, //debug statement
'var_dump' => null, //debug statement
'print_r' => null, //debug statement
'exit' => null,
],
])
->withConfiguredRule(ClassStructureSniff::class, [
'groups' => [
'uses',
'constants',
'enum cases',
'properties',
'constructor',
'static constructors',
'destructor',
'magic methods',
'all public methods',
'all protected methods',
'all private methods',
],
])
->withConfiguredRule(ReferenceUsedNamesOnlySniff::class, [
'searchAnnotations' => true,
'allowFullyQualifiedNameForCollidingClasses' => true,
])
->withRules([
ArrayIndentSniff::class,
SpaceAfterCastSniff::class,
StaticClosureSniff::class,
DisallowSuperGlobalVariableSniff::class,
ClassConstantVisibilitySniff::class,
DeclareStrictTypesFixer::class,
NoExtraBlankLinesFixer::class,
FinalClassFixer::class,
MethodSpacingSniff::class,
UselessAliasSniff::class,
EmptyCommentSniff::class,
UseSpacingSniff::class,
StrictCallSniff::class,
PhpUnitConstructFixer::class,
PhpUnitDedicateAssertFixer::class,
])
;
15 changes: 0 additions & 15 deletions phpcs.xml.dist

This file was deleted.

2 changes: 2 additions & 0 deletions src/Contracts/FinderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
interface FinderFactory
{
public function register(GitHashFinder $finder): void;

public function registerDefaultFinders(): void;

public function getRegisteredFinders(): array;
}
2 changes: 1 addition & 1 deletion src/Exceptions/FindHashException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace TJVB\GitHash\Exceptions;

class FindHashException extends GitHashException
final class FindHashException extends GitHashException
{
}
14 changes: 7 additions & 7 deletions src/Factories/GitHashFinderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ final class GitHashFinderFactory implements FinderFactory
{
private array $finders = [];

public static function withDefaultFinders(): GitHashFinderFactory
{
$factory = new self();
$factory->registerDefaultFinders();
return $factory;
}

public function register(GitHashFinder $finder): void
{
$this->finders[] = $finder;
Expand All @@ -30,11 +37,4 @@ public function getRegisteredFinders(): array
{
return $this->finders;
}

public static function withDefaultFinders(): GitHashFinderFactory
{
$factory = new self();
$factory->registerDefaultFinders();
return $factory;
}
}
1 change: 0 additions & 1 deletion src/HashFinders/GitFileSystemHashFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TJVB\GitHash\HashFinders;

use Exception;
use TJVB\GitHash\Contracts\GitHashFinder;
use TJVB\GitHash\Exceptions\GitHashException;
use TJVB\GitHash\Values\GitHash;
Expand Down
2 changes: 1 addition & 1 deletion src/HashFinders/GitShellExecCommandHashFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public function isAvailable(): bool
}
// shell_exec is a function that is more then once disabled on system.
$disabled = explode(',', ini_get('disable_functions'));
return !in_array('shell_exec', $disabled);
return !in_array('shell_exec', $disabled, true);
}
}
14 changes: 7 additions & 7 deletions src/Retrievers/Retriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ final class Retriever implements GitHashRetriever
{
private ?FinderFactory $finderFactory = null;

public static function getWithFactory(FinderFactory $finderFactory): Retriever
{
$retriever = new self();
$retriever->setFinderFactory($finderFactory);
return $retriever;
}

public function setFinderFactory(FinderFactory $finderFactory): void
{
$this->finderFactory = $finderFactory;
Expand All @@ -36,13 +43,6 @@ public function getHash(string $path): GitHash
throw new GitHashException('No finder available');
}

public static function getWithFactory(FinderFactory $finderFactory): Retriever
{
$retriever = new self();
$retriever->setFinderFactory($finderFactory);
return $retriever;
}

public function getHashAndIgnoreFailures(string $path): GitHash
{
if ($this->finderFactory === null) {
Expand Down
1 change: 0 additions & 1 deletion tests/HashFinders/GitProcessCommandHashFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Tjvb\GitHash\Tests\HashFinders;

use TJVB\GitHash\Exceptions\GitHashException;
use TJVB\GitHash\HashFinders\GitFileSystemHashFinder;
use TJVB\GitHash\HashFinders\GitProcessCommandHashFinder;
use TJVB\GitHash\Tests\TestCase;
use TJVB\GitHash\Values\GitHash;
Expand Down
23 changes: 23 additions & 0 deletions tools/vale/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Core settings appear at the top
# (the "global" section).

StylesPath = styles
MinAlertLevel = suggestion

Packages = proselint, alex

[*.{md,html,yaml}]
BasedOnStyles = Vale, TJVB, proselint, alex

# replaced by TJVB spelling that ignores some technical words
Vale.Spelling = NO
# replaced by TJVB repeatedWords that ignores the cases
Vale.Repetition = no

alex.Ablist = NO
alex.Condescending = NO
alex.ProfanityLikely = NO
alex.ProfanityUnlikely = NO

proselint.Annotations = NO

1 change: 1 addition & 0 deletions tools/vale/ignore-spelling/name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
beek
4 changes: 4 additions & 0 deletions tools/vale/ignore-spelling/tech-words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
laravel
phpstan
config
shell_exec
12 changes: 12 additions & 0 deletions tools/vale/styles/TJVB/Branding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends: substitution
message: Use '%s' instead of '%s'
level: warning
ignorecase: true
# swap maps tokens in form of bad: good
swap:
# NOTE: The left-hand (bad) side can match the right-hand (good) side; Vale
# will ignore any alerts that match the intended form.
'java[ -]?scripts?': JavaScript
'Post?gr?e(?:SQL)': PostgreSQL
'[\s]php?': PHP
'[\s]gitlab?': GitLab
7 changes: 7 additions & 0 deletions tools/vale/styles/TJVB/RepeatedWords.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: repetition
message: "'%s' is repeated!"
level: error
ignorecase: true
alpha: true
tokens:
- '[^\s]+'
6 changes: 6 additions & 0 deletions tools/vale/styles/TJVB/Spelling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends: spelling
message: "Did you really mean '%s'?"
level: error
ignore:
- tools/vale/ignore-spelling/name.txt
- tools/vale/ignore-spelling/tech-words.txt
Loading

0 comments on commit 9e87481

Please sign in to comment.