mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
commit
c6040ed788
@ -1,3 +0,0 @@
|
||||
|
||||
[*.php]
|
||||
indent_size = 4
|
||||
6
php/.gitignore
vendored
6
php/.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
/.idea
|
||||
/report.xml
|
||||
/.phpstorm.meta.php
|
||||
/.phpunit.result.cache
|
||||
/build
|
||||
/vendor
|
||||
/.editorconfig
|
||||
/.phpunit.result.cache
|
||||
/composer.lock
|
||||
|
||||
@ -7,14 +7,15 @@ GildedRose Kata.
|
||||
|
||||
The kata uses:
|
||||
|
||||
- [PHP 7.3 or 7.4 or 8.0+](https://www.php.net/downloads.php)
|
||||
- [8.0+](https://www.php.net/downloads.php)
|
||||
- [Composer](https://getcomposer.org)
|
||||
|
||||
Recommended:
|
||||
|
||||
- [Git](https://git-scm.com/downloads)
|
||||
|
||||
Clone the repository
|
||||
See [GitHub cloning a repository](https://help.github.com/en/articles/cloning-a-repository) for details on how to
|
||||
create a local copy of this project on your computer.
|
||||
|
||||
```sh
|
||||
git clone git@github.com:emilybache/GildedRose-Refactoring-Kata.git
|
||||
@ -41,7 +42,6 @@ The project uses composer to install:
|
||||
- [ApprovalTests.PHP](https://github.com/approvals/ApprovalTests.php)
|
||||
- [PHPStan](https://github.com/phpstan/phpstan)
|
||||
- [Easy Coding Standard (ECS)](https://github.com/symplify/easy-coding-standard)
|
||||
- [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki)
|
||||
|
||||
## Folders
|
||||
|
||||
@ -56,20 +56,30 @@ The project uses composer to install:
|
||||
- `Fixture`
|
||||
- `texttest_fixture.php` this could be used by an ApprovalTests, or run from the command line
|
||||
|
||||
## Fixture
|
||||
|
||||
To run the fixture from the php directory:
|
||||
|
||||
```shell
|
||||
php .\fixtures\texttest_fixture.php 10
|
||||
```
|
||||
|
||||
Change **10** to the required days.
|
||||
|
||||
## Testing
|
||||
|
||||
PHPUnit is configured for testing, a composer script has been provided. To run the unit tests, from the root of the PHP
|
||||
project run:
|
||||
|
||||
```shell script
|
||||
composer test
|
||||
composer tests
|
||||
```
|
||||
|
||||
A Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alias pu="composer test"`), the same
|
||||
PHPUnit `composer test` can be run:
|
||||
A Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alias pu="composer tests"`), the same
|
||||
PHPUnit `composer tests` can be run:
|
||||
|
||||
```shell script
|
||||
pu
|
||||
pu.bat
|
||||
```
|
||||
|
||||
### Tests with Coverage Report
|
||||
@ -83,6 +93,8 @@ composer test-coverage
|
||||
The test-coverage report will be created in /builds, it is best viewed by opening /builds/**index.html** in your
|
||||
browser.
|
||||
|
||||
The [XDEbug](https://xdebug.org/download) extension is required for generating the coverage report.
|
||||
|
||||
## Code Standard
|
||||
|
||||
Easy Coding Standard (ECS) is configured for style and code standards, **PSR-12** is used. The current code is not upto
|
||||
@ -100,7 +112,7 @@ On Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alia
|
||||
PHPUnit `composer check-cs` can be run:
|
||||
|
||||
```shell script
|
||||
cc
|
||||
cc.bat
|
||||
```
|
||||
|
||||
### Fix Code
|
||||
@ -115,7 +127,7 @@ On Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alia
|
||||
PHPUnit `composer fix-cs` can be run:
|
||||
|
||||
```shell script
|
||||
fc
|
||||
fc.bat
|
||||
```
|
||||
|
||||
## Static Analysis
|
||||
@ -130,7 +142,7 @@ On Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alia
|
||||
PHPUnit `composer phpstan` can be run:
|
||||
|
||||
```shell script
|
||||
ps
|
||||
ps.bat
|
||||
```
|
||||
|
||||
**Happy coding**!
|
||||
|
||||
@ -1,8 +1,17 @@
|
||||
{
|
||||
"name": "emilybache/gilded-rose-refactoring-kata",
|
||||
"description": "A kata to practice refactoring, tests and polymorphism",
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0"
|
||||
"php": "^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"approvals/approval-tests": "dev-Main",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"phpstan/phpstan": "^1.9",
|
||||
"phpstan/phpstan-phpunit": "^1.3",
|
||||
"symplify/easy-coding-standard": "^11.1",
|
||||
"symplify/phpstan-extensions": "^11.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -14,18 +23,7 @@
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"phpstan/phpstan": "^0.12.85",
|
||||
"phpstan/phpstan-phpunit": "^0.12.18",
|
||||
"symplify/easy-coding-standard": "^9.3",
|
||||
"symplify/phpstan-extensions": "^9.3",
|
||||
"approvals/approval-tests": "dev-Main"
|
||||
},
|
||||
"scripts": {
|
||||
"checkcode": "phpcs src tests --standard=PSR12",
|
||||
"fixcode": "phpcbf src tests --standard=PSR12",
|
||||
"test": "phpunit",
|
||||
"tests": "phpunit",
|
||||
"test-coverage": "phpunit --coverage-html build/coverage",
|
||||
"check-cs": "ecs check",
|
||||
|
||||
4517
php/composer.lock
generated
4517
php/composer.lock
generated
File diff suppressed because it is too large
Load Diff
49
php/ecs.php
49
php/ecs.php
@ -3,34 +3,45 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symplify\EasyCodingStandard\ValueObject\Option;
|
||||
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
|
||||
use Symplify\EasyCodingStandard\Config\ECSConfig;
|
||||
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(ArraySyntaxFixer::class)
|
||||
->call('configure', [[
|
||||
'syntax' => 'short',
|
||||
]]);
|
||||
// composer require --dev symplify/easy-coding-standard
|
||||
// vendor/bin/ecs init
|
||||
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PATHS, [
|
||||
__DIR__ . '/fixtures',
|
||||
return static function (ECSConfig $ecsConfig): void {
|
||||
$ecsConfig->paths([
|
||||
__DIR__ . '/src',
|
||||
__DIR__ . '/tests',
|
||||
__DIR__ . '/ecs.php', // check this file too!
|
||||
]);
|
||||
|
||||
$parameters->set
|
||||
(Option::SETS,
|
||||
[
|
||||
$ecsConfig->skip([
|
||||
// rules to skip
|
||||
]);
|
||||
|
||||
// run and fix, one by one
|
||||
$ecsConfig->sets([
|
||||
SetList::SPACES,
|
||||
SetList::ARRAY,
|
||||
SetList::DOCBLOCK,
|
||||
SetList::NAMESPACES,
|
||||
SetList::CONTROL_STRUCTURES,
|
||||
SetList::CLEAN_CODE,
|
||||
SetList::COMMON,
|
||||
SetList::STRICT,
|
||||
SetList::PSR_12,
|
||||
]
|
||||
);
|
||||
SetList::PHPUNIT,
|
||||
]);
|
||||
|
||||
$parameters->set(Option::INDENTATION, "spaces");
|
||||
// add declare(strict_types=1); to all php files:
|
||||
$ecsConfig->rule(DeclareStrictTypesFixer::class);
|
||||
|
||||
$parameters->set(Option::LINE_ENDING, "\n");
|
||||
// change $array = array(); to $array = [];
|
||||
$ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [
|
||||
'syntax' => 'short',
|
||||
]);
|
||||
|
||||
// [default: PHP_EOL]; other options: "\n"
|
||||
$ecsConfig->lineEnding("\n");
|
||||
};
|
||||
|
||||
@ -25,7 +25,7 @@ $items = [
|
||||
$app = new GildedRose($items);
|
||||
|
||||
$days = 2;
|
||||
if (count($argv) > 1) {
|
||||
if ((is_countable($argv) ? count($argv) : 0) > 1) {
|
||||
$days = (int) $argv[1];
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ parameters:
|
||||
- tests
|
||||
- fixtures
|
||||
|
||||
# max is the highest level
|
||||
level: max
|
||||
|
||||
checkGenericClassInNonGenericObjectType: false
|
||||
|
||||
@ -1 +1 @@
|
||||
composer test
|
||||
composer tests
|
||||
|
||||
@ -7,13 +7,11 @@ namespace GildedRose;
|
||||
final class GildedRose
|
||||
{
|
||||
/**
|
||||
* @var Item[]
|
||||
* @param Item[] $items
|
||||
*/
|
||||
private $items;
|
||||
|
||||
public function __construct(array $items)
|
||||
{
|
||||
$this->items = $items;
|
||||
public function __construct(
|
||||
private array $items
|
||||
) {
|
||||
}
|
||||
|
||||
public function updateQuality(): void
|
||||
@ -29,12 +27,12 @@ final class GildedRose
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if ($item->sell_in < 11) {
|
||||
if ($item->sellIn < 11) {
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
}
|
||||
if ($item->sell_in < 6) {
|
||||
if ($item->sellIn < 6) {
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
@ -44,10 +42,10 @@ final class GildedRose
|
||||
}
|
||||
|
||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||
$item->sell_in = $item->sell_in - 1;
|
||||
$item->sellIn = $item->sellIn - 1;
|
||||
}
|
||||
|
||||
if ($item->sell_in < 0) {
|
||||
if ($item->sellIn < 0) {
|
||||
if ($item->name != 'Aged Brie') {
|
||||
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if ($item->quality > 0) {
|
||||
|
||||
@ -4,32 +4,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class Item
|
||||
final class Item implements \Stringable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $sell_in;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $quality;
|
||||
|
||||
public function __construct(string $name, int $sell_in, int $quality)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->sell_in = $sell_in;
|
||||
$this->quality = $quality;
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public int $sellIn,
|
||||
public int $quality
|
||||
) {
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "{$this->name}, {$this->sell_in}, {$this->quality}";
|
||||
return (string) "{$this->name}, {$this->sellIn}, {$this->quality}";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user