In this exercise we'll implement from scratch part of the Mars Rover kata.
The rover interface would have only one method: receive(commands: string): void
This is a summary of the behavior of the rover that we'll implement:
<?php | |
class Manager { | |
Worker $worker; | |
// some functions | |
public function doThing() : void { | |
$this->worker->doThing(); | |
} |
// Adapted from Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells | |
<?php | |
class Address { | |
private string $addressLine1; | |
private string $addressLine2; | |
private string $city; | |
private string $state; | |
private string $country; |
<?php | |
// As a direct chain of calls | |
class FlightBooking { | |
// ... | |
public function isSeatAvailable(int $rowNumber, string $seat) : boolean { | |
return $this->plane->getRow($rowNumber)->isAvailable($seat); | |
} | |
} |
// Adapted from Code Smell: Null Check, Joe Eames https://medium.com/thinkster-io/code-smell-null-check-a0c4851fafbf | |
<?php | |
class DiscountCalculator { | |
// ... | |
public function getDiscount(string $customerId) { | |
$customer = $this->customerRepository->findBy($customerId); | |
if($customer == null) { |
// Adapted from Rachel M. Carmena's https://github.com/rachelcarmena/code-smells | |
// see also Ds\Vector in https://www.php.net/manual/en/class.ds-vector.php | |
<?php | |
class CoolStack extends Ds\Vector { | |
public function push(...$values): void { | |
parent::push(...$values); | |
} |
using Xunit; | |
namespace Gilded_rose.Test | |
{ | |
public class GildedRoseTest | |
{ | |
private const int MinQuality = 0; | |
private const int MaxQuality = 50; | |
[Fact] |
package com.gildedrose; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import org.junit.jupiter.api.Test; | |
public class GildedRoseTest { | |
private static final int MIN_QUALITY = 0; |
// Adapted from Code Smell: Null Check, Joe Eames https://medium.com/thinkster-io/code-smell-null-check-a0c4851fafbf | |
class DiscountCalculator { | |
private static final float DEFAULT_DISCOUNT = 1.0f; | |
// ... | |
public float getDiscount(String customerId) { | |
Customer customer = customerRepository.findBy(customerId); | |
if(customer == null) { | |
return DEFAULT_DISCOUNT; | |
} |
// From Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells | |
class Customer { | |
private readonly name: string; | |
private readonly currentAddress: Address; | |
constructor(name: string, address: Address) { | |
this.name = name; | |
this.currentAddress = address; | |
} |