Skip to content

Commit

Permalink
chore: upgrade packages; remove Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Apr 17, 2024
1 parent d64c279 commit d9b11fd
Show file tree
Hide file tree
Showing 31 changed files with 89 additions and 164 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Expand Up @@ -14,8 +14,6 @@
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/psalm-baseline.xml export-ignore
/psalm.xml export-ignore
/resources/ export-ignore
/SECURITY.md export-ignore
/tests/ export-ignore
34 changes: 2 additions & 32 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -66,36 +66,6 @@ jobs:
shell: "bash"
run: "composer dev:analyze:phpstan"

- name: "Statically analyze code (Psalm)"
shell: "bash"
run: "composer dev:analyze:psalm -- --shepherd"

security-analysis:
name: "Security analysis"
needs: ["coding-standards", "static-analysis"]
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3.3.0"

- name: "Install PHP"
uses: "shivammathur/setup-php@2.23.0"
with:
php-version: "latest"
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@2.2.0"

- name: "Analyze security of code (Psalm)"
shell: "bash"
run: "./vendor/bin/psalm --taint-analysis --report=build/logs/psalm.sarif"

- name: "Upload security analysis results to GitHub"
uses: "github/codeql-action/upload-sarif@v2"
with:
sarif_file: "build/logs/psalm.sarif"

code-coverage:
name: "Code coverage"
needs: ["coding-standards", "static-analysis"]
Expand Down Expand Up @@ -123,7 +93,7 @@ jobs:

unit-tests:
name: "Unit tests"
needs: ["code-coverage", "security-analysis"]
needs: ["code-coverage"]
runs-on: ${{ matrix.operating-system }}

strategy:
Expand Down Expand Up @@ -172,7 +142,7 @@ jobs:

functional-tests:
name: "Functional tests"
needs: ["code-coverage", "security-analysis"]
needs: ["code-coverage"]
runs-on: "ubuntu-latest"

strategy:
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -134,9 +134,8 @@ composer dev:lint:fix

### Static Analysis

This project uses a combination of [PHPStan](https://github.com/phpstan/phpstan)
and [Psalm](https://github.com/vimeo/psalm) to provide static analysis of PHP
code.
This project uses [PHPStan](https://github.com/phpstan/phpstan) to provide
static analysis of PHP code.

CaptainHook will run static analysis checks before committing.

Expand Down
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -11,7 +11,6 @@
<a href="https://github.com/ramsey/conventional-commits/blob/main/LICENSE"><img src="https://img.shields.io/packagist/l/ramsey/conventional-commits.svg?style=flat-square&colorB=darkcyan" alt="Read License"></a>
<a href="https://github.com/ramsey/conventional-commits/actions/workflows/continuous-integration.yml"><img src="https://img.shields.io/github/actions/workflow/status/ramsey/conventional-commits/continuous-integration.yml?branch=main&style=flat-square&logo=github" alt="Build Status"></a>
<a href="https://codecov.io/gh/ramsey/conventional-commits"><img src="https://img.shields.io/codecov/c/gh/ramsey/conventional-commits?label=codecov&logo=codecov&style=flat-square" alt="Codecov Code Coverage"></a>
<a href="https://shepherd.dev/github/ramsey/conventional-commits"><img src="https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fshepherd.dev%2Fgithub%2Framsey%2Fconventional-commits%2Fcoverage" alt="Psalm Type Coverage"></a>
</p>

## About
Expand Down
18 changes: 6 additions & 12 deletions composer.json
Expand Up @@ -42,17 +42,14 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.5",
"psalm/plugin-mockery": "^1.1",
"psalm/plugin-phpunit": "^0.18.4",
"phpunit/phpunit": "^10.1",
"ramsey/coding-standard": "^2.2",
"ramsey/composer-repl": "^1.4",
"roave/security-advisories": "dev-latest",
"sebastianfeldmann/cli": "^3.4",
"sebastianfeldmann/git": "^3.8",
"spatie/phpunit-snapshot-assertions": "^4.2",
"symfony/process": "^6.0",
"vimeo/psalm": "^5.8"
"spatie/phpunit-snapshot-assertions": "^5.1",
"symfony/process": "^6.0 || ^7.0"
},
"suggest": {
"captainhook/captainhook": "Manage your project's Git hooks with CaptainHook, and use ramsey/conventional-commits in your commit-msg and prepare-commit-msg hooks."
Expand All @@ -75,10 +72,10 @@
],
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"captainhook/plugin-composer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"captainhook/plugin-composer": true,
"phpstan/extension-installer": true,
"ramsey/composer-repl": true
},
"sort-packages": true
Expand All @@ -96,11 +93,9 @@
},
"scripts": {
"dev:analyze": [
"@dev:analyze:phpstan",
"@dev:analyze:psalm"
"@dev:analyze:phpstan"
],
"dev:analyze:phpstan": "phpstan analyse --ansi --memory-limit 256M",
"dev:analyze:psalm": "psalm",
"dev:build:clean": "git clean -fX build/",
"dev:lint": [
"@dev:lint:syntax",
Expand All @@ -124,7 +119,6 @@
"scripts-descriptions": {
"dev:analyze": "Runs all static analysis checks.",
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.",
"dev:analyze:psalm": "Runs the Psalm static analyzer.",
"dev:build:clean": "Cleans the build/ directory.",
"dev:lint": "Runs all linting checks.",
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.",
Expand Down
7 changes: 3 additions & 4 deletions phpunit.xml.dist
Expand Up @@ -2,21 +2,20 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
cacheResultFile="./build/cache/phpunit.result.cache"
colors="true"
verbose="true">
cacheDirectory="./build/cache/phpunit">

<testsuites>
<testsuite name="unit-tests">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>

<php>
<!-- Turn off console color output for easier testing of output strings. -->
Expand Down
18 changes: 0 additions & 18 deletions psalm.xml

This file was deleted.

1 change: 0 additions & 1 deletion src/CaptainHook/Input.php
Expand Up @@ -39,7 +39,6 @@ public function __construct(IO $captainHookIO)
$definition = new InputDefinition();

/**
* @psalm-suppress UnnecessaryVarAnnotation
* @var string $key
*/
foreach (array_keys($captainHookIO->getArguments()) as $key) {
Expand Down
2 changes: 1 addition & 1 deletion src/CaptainHook/PrepareConventionalCommit.php
Expand Up @@ -41,7 +41,7 @@
* During the prepare-commit-msg Git hook, this prompts the user for input and
* builds a valid Conventional Commits commit message
*
* @psalm-import-type ConfigurationOptionsType from Configuration
* @phpstan-import-type ConfigurationOptionsType from Configuration
*/
class PrepareConventionalCommit implements Action, Constrained
{
Expand Down
2 changes: 1 addition & 1 deletion src/CaptainHook/ValidateConventionalCommit.php
Expand Up @@ -41,7 +41,7 @@
* During the commit-msg Git hook, this validates the commit message according
* to the Conventional Commits specification
*
* @psalm-import-type ConfigurationOptionsType from Configuration
* @phpstan-import-type ConfigurationOptionsType from Configuration
*/
class ValidateConventionalCommit implements Action, Constrained
{
Expand Down
4 changes: 2 additions & 2 deletions src/ConventionalCommits/Configuration/Configuration.php
Expand Up @@ -29,14 +29,14 @@
* A configuration provides additional rules on top of the Conventional
* Commits specification
*
* @psalm-type ConfigurationOptionsType = array{typeCase?: string | null, types?: string[], scopeCase?: string | null, scopeRequired?: bool, scopes?: string[], descriptionCase?: string | null, descriptionEndMark?: string | null, bodyRequired?: bool, bodyWrapWidth?: int | null, requiredFooters?: string[]}
* @phpstan-type ConfigurationOptionsType array{typeCase?: string | null, types?: string[], scopeCase?: string | null, scopeRequired?: bool, scopes?: string[], descriptionCase?: string | null, descriptionEndMark?: string | null, bodyRequired?: bool, bodyWrapWidth?: int | null, requiredFooters?: string[]}
*/
interface Configuration extends JsonSerializable
{
/**
* Returns the configuration as an array
*
* @psalm-return ConfigurationOptionsType
* @return ConfigurationOptionsType
*/
public function toArray(): array;

Expand Down
Expand Up @@ -41,7 +41,7 @@
/**
* Default configuration for Conventional Commits commit messages
*
* @psalm-import-type ConfigurationOptionsType from Configuration
* @phpstan-import-type ConfigurationOptionsType from Configuration
*/
class DefaultConfiguration implements Configuration
{
Expand Down Expand Up @@ -70,7 +70,7 @@ class DefaultConfiguration implements Configuration
private ?MessageValidator $messageValidator = null;

/**
* @psalm-param ConfigurationOptionsType $options
* @param ConfigurationOptionsType $options
*/
public function __construct(array $options = [])
{
Expand Down Expand Up @@ -110,8 +110,7 @@ public function toArray(): array
}

/**
* @psalm-return ConfigurationOptionsType
* @psalm-suppress UndefinedAttributeClass
* @return ConfigurationOptionsType
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
Expand Down Expand Up @@ -214,7 +213,7 @@ public function getMessageValidator(): MessageValidator
}

/**
* @psalm-param ConfigurationOptionsType $options
* @param ConfigurationOptionsType $options
*/
private function caseIfValid(array $options, string $parameter): ?string
{
Expand Down
1 change: 0 additions & 1 deletion src/ConventionalCommits/Configuration/FinderTool.php
Expand Up @@ -195,7 +195,6 @@ private function validateConfig(object $config): bool
);
}

/** @psalm-suppress MixedArgumentTypeCoercion */
throw new InvalidValue($messages);
}

Expand Down
21 changes: 3 additions & 18 deletions src/ConventionalCommits/Console/Command/PrepareCommand.php
Expand Up @@ -118,25 +118,21 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
private function askQuestions(SymfonyStyle $console): Message
{
/**
* @psalm-suppress ReservedWord
* @var Type $type
*/
$type = $console->askQuestion(new TypeQuestion($this->getConfiguration()));

/**
* @psalm-suppress ReservedWord
* @var Scope|null $scope
*/
$scope = $console->askQuestion(new ScopeQuestion($this->getConfiguration()));

/**
* @psalm-suppress ReservedWord
* @var Description $description
*/
$description = $console->askQuestion(new DescriptionQuestion($this->getConfiguration()));

/**
* @psalm-suppress ReservedWord
* @var Body|null $body
*/
$body = $console->askQuestion(new BodyQuestion($this->getConfiguration()));
Expand Down Expand Up @@ -171,13 +167,8 @@ private function askFooterQuestions(SymfonyStyle $console): array
{
$footers = [];

/**
* @psalm-suppress RedundantCondition
* @psalm-suppress ReservedWord
*/
if ($console->askQuestion(new HasBreakingChangesQuestion())) {
/**
* @psalm-suppress ReservedWord
* @var Footer $breakingChanges
*/
$breakingChanges = $console->askQuestion(new DescribeBreakingChangesQuestion());
Expand All @@ -203,9 +194,9 @@ private function askFooterQuestions(SymfonyStyle $console): array
}

/**
* @return Footer[]
* @param Closure(string):Question $valueQuestionCallback
*
* @psalm-param Closure(string):Question $valueQuestionCallback
* @return Footer[]
*/
private function askFooterQuestionSection(
SymfonyStyle $console,
Expand All @@ -214,10 +205,6 @@ private function askFooterQuestionSection(
Closure $valueQuestionCallback,
bool $isRequired = false,
): array {
/**
* @psalm-suppress ReservedWord
* @psalm-suppress TypeDoesNotContainType
*/
if (!$isRequired && !$console->askQuestion($decisionPathQuestion)) {
return [];
}
Expand All @@ -236,15 +223,14 @@ private function askFooterQuestionSection(
}

/**
* @psalm-param Closure(string):Question $valueQuestionCallback
* @param Closure(string):Question $valueQuestionCallback
*/
private function askFooterQuestion(
SymfonyStyle $console,
Question $tokenQuestion,
Closure $valueQuestionCallback,
): ?Footer {
/**
* @psalm-suppress ReservedWord
* @var string|null $token
*/
$token = $console->askQuestion($tokenQuestion);
Expand All @@ -254,7 +240,6 @@ private function askFooterQuestion(
}

/**
* @psalm-suppress ReservedWord
* @var Footer|null $footer
*/
$footer = $console->askQuestion($valueQuestionCallback($token));
Expand Down
Expand Up @@ -76,7 +76,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
if ($message === null) {
$console->title('Validate Commit Message');
/**
* @psalm-suppress ReservedWord
* @var string|null $message
*/
$message = $console->askQuestion(new MessageQuestion($this->getConfiguration()));
Expand Down
16 changes: 4 additions & 12 deletions src/ConventionalCommits/Parser.php
Expand Up @@ -110,21 +110,13 @@ private function parseFooter(string $footer): array
return [];
}

/**
* Psalm needs this because there's no way to define the array structure
* above the preg_match_all() statement where $matches is instantiated.
*
* @var array{token: list<string>, separator: list<string>, value: list<string>} $footerParams
*/
$footerParams = $matches;

$footers = [];

for ($i = 0; $i < count($footerParams['token']); $i++) {
for ($i = 0; $i < count($matches['token']); $i++) {
$footers[] = new Footer(
$footerParams['token'][$i],
$footerParams['value'][$i],
$footerParams['separator'][$i],
$matches['token'][$i],
$matches['value'][$i],
$matches['separator'][$i],
);
}

Expand Down

0 comments on commit d9b11fd

Please sign in to comment.