Skip to content

zacarias-calabria/Parrot-Refactoring-Kata

Repository files navigation

Parrot Refactoring Kata

Can you spot any code smells in this code? I'll give you a clue - a spot of Pol(l)ymorphism should improve matters!

Refactor this code, take small steps, run the tests often. See how small and beautiful and polymorphic you can make it.

Emily Bache made a video about this kata: From Hello Polly! to Polymorphism: Parrot Refactoring Code Kata is FUN.

This is the PHP version of the Kata. The Kata is fully functional, with a full test suite. The tests do not normally need to be changed.

Acknowlegements

This code is heavily inspired by one of the examples in Martin Fowler's book "Refactoring". It's a classic, and if it's not on your bookshelf already I suggest you treat yourself to a copy!

Thanks also to Fran Iglesias for the teachings and for sharing his knowledge and experience in the refactoring to polymorphism exercise of the Emily Blanche Parrot Refactoring Kata.

Installation

The kata uses:

Recommended:

See GitHub cloning a repository for details on how to create a local copy of this project on your computer.

git clone https://github.com/emilybache/Parrot-Refactoring-Kata.git

Install all the dependencies using composer

cd Parrot-Refactoring-Kata/PHP
composer install

Run all the tests

composer tests

Dependencies

The kata uses composer to install:

Folders

  • src - contains the Parrot class which need to be refactored and a ParrotType.
  • tests - contains the corresponding tests. All the tests are passing, and shouldn't need to be changed.

Testing

PHPUnit is pre-configured to run tests. PHPUnit can be run using a composer script. To run the unit tests, from the root of the PHP kata run:

composer tests

On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. alias pu="composer test"), the same PHPUnit composer test can be run:

pu.bat

Tests with Coverage Report

To run all test and generate a html coverage report run:

composer test-coverage

The test-coverage report will be created in /builds, it is best viewed by opening /builds/index.html in your browser.

Code Standard

Easy Coding Standard (ECS) is used to check for style and code standards, PSR-12 is used.

Check Code

To check code, but not fix errors:

composer check-cs

On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. alias cc="composer check-cs"), the same composer check-cs can be run:

cc.bat

Fix Code

There are many code fixes automatically provided by ECS, if advised to run --fix, the following script can be run:

composer fix-cs

On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. alias fc="composer fix-cs"), the same composer fix-cs can be run:

fc.bat

Static Analysis

PHPStan is used to run static analysis checks:

composer phpstan

On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. alias ps="composer phpstan"), the same composer phpstan can be run:

ps.bat

Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published