Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CS errors and adapt threshold #159

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Determine the base branch for the file diff
id: base_branch
env:
BASE_REF: ${{ github.base_ref }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "NAME=$BASE_REF" >> $GITHUB_OUTPUT
echo "REF=origin/$BASE_REF" >> $GITHUB_OUTPUT
else
echo 'NAME=main' >> $GITHUB_OUTPUT
echo "REF=origin/main" >> $GITHUB_OUTPUT
fi

- name: Fetch base branch
run: git fetch --no-tags --depth=1 origin ${{ steps.base_branch.outputs.NAME }}

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -76,18 +60,12 @@ jobs:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

# Check the codestyle of the files against a threshold of expected errors and warnings.
- name: Check PHP code style against the thresholds
run: composer check-cs-thresholds

# Check the codestyle only of the files which were changed in the current branch.
# This step will only be executed if the threshold check exited with a failure status.
# The results of this CS check will be shown inline in the PR via the CS2PR tool.
# Check the codestyle of the files.
# The results of the CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- name: Check PHP code style for the changes made in the branch only
if: ${{ failure() }}
- name: Check PHP code style
id: phpcs
run: composer check-branch-cs -- ${{ steps.base_branch.outputs.REF }}
run: composer check-cs-warnings -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"Yoast\\WHIP\\Config\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=10",
"@putenv YOASTCS_THRESHOLD_ERRORS=0",
"@putenv YOASTCS_THRESHOLD_WARNINGS=0",
"Yoast\\WHIP\\Config\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class Configuration {
/**
* The configuration to use.
*
* @var array
* @var array<string>
*/
private $configuration;

/**
* Configuration constructor.
*
* @param array $configuration The configuration to use.
* @param array<string> $configuration The configuration to use.
*
* @throws InvalidType When the $configuration parameter is not of the expected type.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Exceptions/InvalidVersionComparisonString.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Exception for an invalid version comparison string.
*
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- Name should be descriptive and was historically (before namespacing) already set to this.
*/
class InvalidVersionComparisonString extends Exception {

Expand Down
2 changes: 1 addition & 1 deletion src/Facades/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Facade to quickly check if version requirements are met.
*
* @param array $requirements The requirements to check.
* @param array<string> $requirements The requirements to check.
*
* @return void
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Messages/InvalidVersionRequirementMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Class Whip_InvalidVersionMessage.
*
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- Name should be descriptive and was historically (before namespacing) already set to this.
*/
class InvalidVersionRequirementMessage implements Message {

Expand Down
6 changes: 3 additions & 3 deletions src/MessagesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function hasMessages() {
/**
* Lists the messages that are currently available.
*
* @return array The messages that are currently set.
* @return array<Message> The messages that are currently set.
*/
public function listMessages() {
return $GLOBALS['whip_messages'];
Expand Down Expand Up @@ -79,9 +79,9 @@ public function getLatestMessage() {
/**
* Sorts the list of messages based on the version number.
*
* @param array $messages The list of messages to sort.
* @param array<Message> $messages The list of messages to sort.
*
* @return array The sorted list of messages.
* @return array<Message> The sorted list of messages.
*/
private function sortByVersion( array $messages ) {
\uksort( $messages, 'version_compare' );
Expand Down
6 changes: 3 additions & 3 deletions src/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RequirementsChecker {
/**
* Requirements the environment should comply with.
*
* @var array
* @var array<Requirement>
*/
private $requirements;

Expand Down Expand Up @@ -44,8 +44,8 @@ class RequirementsChecker {
/**
* RequirementsChecker constructor.
*
* @param array $configuration The configuration to check.
* @param string $textdomain The text domain to use for translations.
* @param array<Requirement> $configuration The configuration to check.
* @param string $textdomain The text domain to use for translations.
*
* @throws InvalidType When the $configuration parameter is not of the expected type.
*/
Expand Down