diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7090b27 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +# https://EditorConfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +block_comment_start = /* +block_comment = * +block_comment_end = */ + +[*.yml] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[*.json] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 4e9c1de..4d54c8e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,3 @@ -/Tests export-ignore /.* export-ignore -/phpstan.neon.dist export-ignore -/phpunit.xml.dist export-ignore \ No newline at end of file +/Tests export-ignore +/phpunit.xml.dist export-ignore diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml new file mode 100644 index 0000000..61c1c57 --- /dev/null +++ b/.github/workflows/integrate.yml @@ -0,0 +1,181 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow + +name: "Integrate" + +on: + push: + branches: + - "main" + - "develop" + pull_request: + branches: + - "main" + - "develop" + # Add [skip ci] to commit message to skip CI. + +permissions: + contents: "read" + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + byte_level: + name: "0️⃣ Byte-level" + runs-on: "ubuntu-latest" + steps: + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Check file permissions" + run: | + test "$(find . -type f -not -path './.git/*' -executable)" = "" + + - name: "Find non-printable ASCII characters" + run: | + ! LC_ALL=C.UTF-8 find . -type f -name '*.php' -print0 | xargs -0 -- grep -PHn '[^ -~]' + + syntax_errors: + name: "1️⃣ Syntax errors" + runs-on: "ubuntu-latest" + steps: + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "8.0" + coverage: "none" + + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Install dependencies" + uses: "ramsey/composer-install@v2" + with: + dependency-versions: "highest" + + - name: "Check source code for syntax errors" + run: "composer exec -- parallel-lint Src/ Tests/" + + unit_tests: + name: "2️⃣ Unit and functional tests" + needs: + - "byte_level" + - "syntax_errors" + strategy: + #fail-fast: false + matrix: + php-version: + - "8.0" + - "8.1" + - "8.2" + dependencies: + - "lowest" + - "highest" + runs-on: "ubuntu-latest" + steps: + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Install dependencies" + uses: "ramsey/composer-install@v2" + with: + dependency-versions: "${{ matrix.dependencies }}" + + - name: "Execute unit tests" + run: "composer run-script test" + +# - name: "Send coverage to Coveralls" +# env: +# COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}" +# if: "${{ env.COVERALLS_REPO_TOKEN && matrix.php-version == '8.0' && matrix.dependencies == 'highest' }}" +# run: | +# wget "https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.2/php-coveralls.phar" +# php ./php-coveralls.phar -v + + static_analysis: + name: "3️⃣ Static Analysis" + needs: + - "byte_level" + - "syntax_errors" + runs-on: "ubuntu-latest" + steps: + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "8.0" + coverage: "none" + + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Check JSON files" + run: | + find . -type f -name '*.json' | xargs -t -L 1 -- php -r 'json_decode(file_get_contents($argv[1]), null, 512, JSON_THROW_ON_ERROR);' + + - name: "Validate Composer configuration" + run: "composer validate --no-interaction --strict" + + - name: "Install dependencies" + uses: "ramsey/composer-install@v2" + with: + dependency-versions: "highest" + + - name: "Check PSR-4 mapping" + run: "composer dump-autoload --no-interaction --optimize --strict-psr" + + - name: "Perform static analysis" + run: "composer run-script phpstan" + + coding_standards: + name: "4️⃣ Coding Standards" + needs: + - "byte_level" + - "syntax_errors" + runs-on: "ubuntu-latest" + steps: + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "8.0" + coverage: "none" + + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Check EditorConfig configuration" + run: "test -f .editorconfig" + + - name: "Check adherence to EditorConfig" + uses: "greut/eclint-action@v0" + + - name: "Install dependencies" + uses: "ramsey/composer-install@v2" + with: + dependency-versions: "highest" + + - name: "Check coding style" + run: "composer exec -- phpcs --standard=PSR12 -s Src/ Tests/" + + exported_files: + name: "5️⃣ Exported files" + needs: + - "byte_level" + - "syntax_errors" + runs-on: "ubuntu-latest" + steps: + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Check exported files" + run: | + EXPECTED="CHANGELOG.md,LICENSE,README.md,composer.json" + CURRENT="$(git archive HEAD | tar --list --exclude="Src" --exclude="Src/*" | paste --serial --delimiters=",")" + echo "CURRENT =${CURRENT}" + echo "EXPECTED=${EXPECTED}" + test "${CURRENT}" = "${EXPECTED}" diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml deleted file mode 100644 index ad426bd..0000000 --- a/.github/workflows/php.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: PHP Composer - -on: - push: - branches: [ "main", "develop" ] - pull_request: - branches: [ "main", "develop" ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md - - - name: Run test suite - run: composer run-script test - - name: Run static analyzer - run: composer run-script phpstan - diff --git a/.gitignore b/.gitignore index 34cf04b..bf3083f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -vendor -.phpunit.result.cache \ No newline at end of file +/.phpunit.result.cache +/vendor/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da6430..e1bc4a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -* Renamed the package in Packagist from `php-weather/common` to `php-weather/core`(#1) \ No newline at end of file +* Renamed the package in Packagist from `php-weather/common` to `php-weather/core`(#1) diff --git a/Src/Common/Source.php b/Src/Common/Source.php index 5c41eeb..acb796d 100644 --- a/Src/Common/Source.php +++ b/Src/Common/Source.php @@ -53,4 +53,4 @@ public function toArray(): array { return get_object_vars($this); } -} \ No newline at end of file +} diff --git a/Src/Common/UnitConverter.php b/Src/Common/UnitConverter.php index 10c2f9e..de9848e 100644 --- a/Src/Common/UnitConverter.php +++ b/Src/Common/UnitConverter.php @@ -146,4 +146,4 @@ public static function mapPrecipitation(float $precipitation, string $from, stri }, }; } -} \ No newline at end of file +} diff --git a/Src/Common/Weather.php b/Src/Common/Weather.php index 56cb63a..a14ab1e 100644 --- a/Src/Common/Weather.php +++ b/Src/Common/Weather.php @@ -262,4 +262,4 @@ public function setDewPoint(?float $dewPoint): self return $this; } -} \ No newline at end of file +} diff --git a/Src/Common/WeatherCollection.php b/Src/Common/WeatherCollection.php index ac0523f..e56ec99 100644 --- a/Src/Common/WeatherCollection.php +++ b/Src/Common/WeatherCollection.php @@ -222,4 +222,4 @@ private function sortByDate(Weather $a, Weather $b): int return ($a->getUtcDateTime() < $b->getUtcDateTime()) ? -1 : 1; } -} \ No newline at end of file +} diff --git a/Src/Common/WeatherQuery.php b/Src/Common/WeatherQuery.php index 4795d77..a1b29b0 100644 --- a/Src/Common/WeatherQuery.php +++ b/Src/Common/WeatherQuery.php @@ -97,4 +97,4 @@ public function getUnits(): string { return $this->units; } -} \ No newline at end of file +} diff --git a/Src/Constants/Type.php b/Src/Constants/Type.php index f837a8e..5b7a1a9 100644 --- a/Src/Constants/Type.php +++ b/Src/Constants/Type.php @@ -12,4 +12,4 @@ class Type public const CURRENT = 'current'; public const HISTORICAL = 'historical'; public const FORECAST = 'forecast'; -} \ No newline at end of file +} diff --git a/Src/Constants/Unit.php b/Src/Constants/Unit.php index f09b6ec..de3a83e 100644 --- a/Src/Constants/Unit.php +++ b/Src/Constants/Unit.php @@ -26,4 +26,4 @@ class Unit public const PRECIPITATION_MM = 'mm'; public const PRECIPIATION_kgm = 'kgm'; public const PRECIPITAION_INCHES = 'inches'; -} \ No newline at end of file +} diff --git a/Src/Exception.php b/Src/Exception.php index 2ef8694..94185cc 100644 --- a/Src/Exception.php +++ b/Src/Exception.php @@ -7,4 +7,4 @@ interface Exception extends Throwable { -} \ No newline at end of file +} diff --git a/Src/Exception/ClientException.php b/Src/Exception/ClientException.php index 9ad8eb2..f26e753 100644 --- a/Src/Exception/ClientException.php +++ b/Src/Exception/ClientException.php @@ -6,4 +6,4 @@ class ClientException extends WeatherException { -} \ No newline at end of file +} diff --git a/Src/Exception/InvalidCredentials.php b/Src/Exception/InvalidCredentials.php index 8541fc7..a7334a3 100644 --- a/Src/Exception/InvalidCredentials.php +++ b/Src/Exception/InvalidCredentials.php @@ -6,4 +6,4 @@ class InvalidCredentials extends ClientException { -} \ No newline at end of file +} diff --git a/Src/Exception/InvalidValueException.php b/Src/Exception/InvalidValueException.php index 6ee4772..0cb8739 100644 --- a/Src/Exception/InvalidValueException.php +++ b/Src/Exception/InvalidValueException.php @@ -6,4 +6,4 @@ class InvalidValueException extends WeatherException { -} \ No newline at end of file +} diff --git a/Src/Exception/NoWeatherData.php b/Src/Exception/NoWeatherData.php index 265f569..128d287 100644 --- a/Src/Exception/NoWeatherData.php +++ b/Src/Exception/NoWeatherData.php @@ -6,4 +6,4 @@ class NoWeatherData extends WeatherException { -} \ No newline at end of file +} diff --git a/Src/Exception/QuotaExceeded.php b/Src/Exception/QuotaExceeded.php index 09a980e..99801a4 100644 --- a/Src/Exception/QuotaExceeded.php +++ b/Src/Exception/QuotaExceeded.php @@ -6,4 +6,4 @@ class QuotaExceeded extends ClientException { -} \ No newline at end of file +} diff --git a/Src/Exception/ServerException.php b/Src/Exception/ServerException.php index 83389fa..35dbf67 100644 --- a/Src/Exception/ServerException.php +++ b/Src/Exception/ServerException.php @@ -6,4 +6,4 @@ class ServerException extends WeatherException { -} \ No newline at end of file +} diff --git a/Src/Exception/WeatherException.php b/Src/Exception/WeatherException.php index 7749b57..ad3c1b1 100644 --- a/Src/Exception/WeatherException.php +++ b/Src/Exception/WeatherException.php @@ -8,4 +8,4 @@ class WeatherException extends \Exception implements Exception { -} \ No newline at end of file +} diff --git a/Src/Provider.php b/Src/Provider.php index b5b18bd..52719f8 100644 --- a/Src/Provider.php +++ b/Src/Provider.php @@ -43,4 +43,4 @@ public function getHistoricalTimeLine(WeatherQuery $query): WeatherCollection; * @return Source[] */ public function getSources(): array; -} \ No newline at end of file +} diff --git a/Src/Weather.php b/Src/Weather.php index 805ae8e..ce899b0 100644 --- a/Src/Weather.php +++ b/Src/Weather.php @@ -55,4 +55,4 @@ public function setIcon(?string $icon): self; public function getSources(): array; public function addSource(Source $source): self; public function removeSource(Source $source): self; -} \ No newline at end of file +} diff --git a/Src/WeatherCollection.php b/Src/WeatherCollection.php index 6afbc71..cc49649 100644 --- a/Src/WeatherCollection.php +++ b/Src/WeatherCollection.php @@ -31,4 +31,4 @@ public function hasForecast(): bool; * @return Weather[]; */ public function getForecast(): array; -} \ No newline at end of file +} diff --git a/Src/WeatherQuery.php b/Src/WeatherQuery.php index 20c05a9..21851b2 100644 --- a/Src/WeatherQuery.php +++ b/Src/WeatherQuery.php @@ -20,4 +20,4 @@ public function getLongitude(): float; public function getDateTime(): ?DateTimeInterface; public function getTimestamp(): ?int; public function getUnits(): string; -} \ No newline at end of file +} diff --git a/Tests/WeatherCollectionTest.php b/Tests/WeatherCollectionTest.php index 51f9ab4..69a1a06 100644 --- a/Tests/WeatherCollectionTest.php +++ b/Tests/WeatherCollectionTest.php @@ -1,6 +1,11 @@ =8.0" + "phpunit/phpunit": ">=8.0", + "squizlabs/php_codesniffer": "^3.7" }, "autoload": { "psr-4": { - "PhpWeather\\": "Src" + "PhpWeather\\": "Src/" } }, "autoload-dev": { "psr-4": { - "PhpWeather\\": "Tests" + "PhpWeather\\Tests\\": "Tests/" } }, "scripts": { "test": "phpunit", - "phpstan": "phpstan analyse Src --level=8" + "phpstan": "phpstan analyse --level=8 Src/" }, "config": { "lock": false, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 61300bb..b36807d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,10 @@ -