Skip to content
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
11 changes: 6 additions & 5 deletions .github/workflows/exercise-lint-phpcs-psr-12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ jobs:

- uses: shivammathur/setup-php@46fc8a2fd7cba50512858026dc8f0947c8a7a0e8
with:
version: ${{ matrix.php-version }}
php-version: ${{ matrix.php-version }}
extensions: gmp
tools: composer

- name: Install dependencies
shell: bash
run: |
curl -Lo bin/phpcs.phar https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
chmod +x bin/phpcs.phar

- name: Install composer packages
run: composer install

- name: Lint exercises
shell: bash
env:
PHPCS_BIN: 'bin/phpcs.phar'
PHPCS_RULES: 'phpcs-php.xml'
run: bin/lint.sh
run: composer lint:check
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ tmp
.phpunit.result.cache
bin/configlet
bin/configlet.exe

/vendor/
composer.lock
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "exercism/php",
"autoload": {
"Exercism\\": "src",
"Exercism\\Exercises\\": "exercises"
},
"require-dev": {
"php": "^7.4|^8.0",
"slevomat/coding-standard": "^7.0",
"squizlabs/php_codesniffer": "^3.6"
},
"scripts": {
"lint:check": "./vendor/bin/phpcs --standard=phpcs-php.xml ./exercises",
"lint:fix": "./vendor/bin/phpcbf --standard=phpcs-php.xml ./exercises"
}
}
24 changes: 24 additions & 0 deletions exercises/practice/accumulate/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

/**
* Given the input array and operation returns an array
* containing the result of applying that operation
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/accumulate/Accumulate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function accumulate(array $input, callable $accumulator): array
{
throw new \BadFunctionCallException("Implement the accumulate function");
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/accumulate/AccumulateTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class AccumulateTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/acronym/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

/**
* Abbreviates a phrase.
*
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/acronym/Acronym.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function acronym(string $text): string
{
throw new \BadFunctionCallException("Implement the acronym function");
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/acronym/AcronymTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class AcronymTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/affine-cipher/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function encode($text, $a, $b)
{
$alphabet = range('a', 'z');
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/affine-cipher/AffineCipher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function encode(string $text, int $num1, int $num2): string
{
throw new \BadFunctionCallException("Implement the encode function");
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/affine-cipher/AffineCipherTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

/**
* The test are divided into two groups:
*
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/all-your-base/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function rebase(int $fromBase, array $digits, int $toBase)
{
if (empty($digits) || $digits[0] == 0 || $fromBase <= 1 || $toBase <= 1) {
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/all-your-base/AllYourBase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function rebase(int $number, array $sequence, int $base)
{
throw new \BadFunctionCallException("Implement the rebase function");
Expand Down
Loading