Code Monkey home page Code Monkey logo

gilded-rose-refactoring-kata-php's Introduction

Gilded Rose Refactoring Kata PHP

This is the the refactored version of the original Gilded Rose Refactoring Kata in PHP. Package comes with created PHP unit tests, refactoring done and new feature added.

The Gilded Rose Requirements can be found here.

Requirements

  • PHP 7.2 or greater.
  • You might need some extra PHP packages like php-xml. Just follow on screen instructions.
  • Composer.

Setup

To install the project you need:

  1. Clone repository to desired directory git clone [email protected]:mantis4444/gilded-rose-refactoring-kata-php.git /desired/directory.
  2. Enter project directory cd /desired/directory.
  3. Install the project composer install.

Note that if you are doing it on Windows OS you need to use \ instead of / for directory separation.

Usage

  • To execute defined instructions of the application you need to excute the texttest_fixture.php file with the command php src/texttest_fixture.php.
  • Instructions of the applications can be edited in src/texttest_fixture.php file.
  • The results are returned on the terminal screen.
  • You can execute PHPUnit tests with ./vendor/bin/phpunit.

Note that these instructions assumes that you are in the project directory.

Dev notes

I kept the original coding style to adapt to current situation. Though I would have liked to use PSR standard and namespaces. As a result application supports original input, thus the texttest_fixture.php file was not touched.

First of all I made tests to make sure that original code is working properly and suprisngly it was, despite its messy algorythm structure. Then refactoring process started. In the beginning I shrinked the update_quality() function as much as possible. Code became much more readable, but there were still too many conditional if and I did not see a way how I could minimize it more.

After doing some analysis I realised that Polymorphism is the solution. First of all I created enhanced item class called ItemEnhanced which was extending original and untouchable Item class to improve its functionality. The first challange was to enhance Items and support original instruction code. While original code is setting up items with Item class I had to find a way to enhance items without changing it. I made it on the GildedRose app initialization constructor, enhancing Items while setting them. To make the original item object enhance too, I used reference links.

Now class ItemEnhanced has the funcionality that all type of items share. On the next step I created class for every type of item that they would have their own special funcionality. They are extending the ItemEnhanced class thus the original Item also. Functions of the ItemEnhanced that are being used only in those item type classes are protected for the accesibility in item type class only.

After refactoring is finished, tests are passing successfully. Now it was a time to add new funcionality. Having new structure of the application it was easy to do that. First I created new item type class for "Conjured" item with its specific rules. Then I created new tests for it.

Voila everything works like a charm, code is much more readable and flexible. I would say that the tests could be improved a lot. They could be much more specific than they are now.

gilded-rose-refactoring-kata-php's People

Contributors

mantis4444 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.