Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #26

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
vendor/
.phpunit.result.cache/
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"FooBarTest::test_is_result_foo":4,"FooBarTest::test_is_result_bar":4,"FooBarTest::test_is_result_foo_bar":3,"FooBarTest::test_is_result_qix":3,"FooBarQixTest::test_is_result_qix":3,"FooBarQixTest::test_is_result_foo_qix":3,"FooBarQixTest::test_is_result_bar_qix":3,"FooBarQixTest::test_is_result_foo_bar_qix":3,"FooBarQixOccurrencesTest::test_is_result_foo":3,"FooBarQixOccurrencesTest::test_is_result_foo_qix":3,"FooBarQixOccurrencesTest::test_is_result_qix_foo":3,"FooBarQixOccurrencesTest::test_is_result_bar_foo":3,"FooBarQixOccurrencesTest::test_is_result_bar_qix":3,"FooBarQixCombinedTest::test_is_result_foo_foo":3,"FooBarQixCombinedTest::test_is_result_bar_bar":3,"FooBarQixCombinedTest::test_is_result_qix_qix":3,"FooBarQixCombinedTest::test_is_result_foo_qix":3,"FooBarQixCombinedTest::test_is_result_qix_foo":3,"FooBarQixCombinedTest::test_is_result_bar_foo":3,"FooBarQixCombinedTest::test_is_result_bar_qix":3,"FooBarQixCombinedTest::test_is_result_qix_bar":3,"FooBarQixCombinedTest::test_is_result_foo_bar":3,"FooBarQixMultiplesTest::test_is_result_foo":3,"FooBarQixMultiplesTest::test_is_result_bar":3,"FooBarQixMultiplesTest::test_is_result_qix":3,"FooBarQixMultiplesTest::test_is_result_foo_bar":3,"FooBarQixMultiplesTest::test_is_result_foo_qix":3,"FooBarQixMultiplesTest::test_is_result_bar_qix":3,"FooBarQixMultiplesTest::test_is_result_foo_bar_qix":3,"FooBarQixOccurrencesTest::test_is_result_qix":3,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_foo_foo":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_bar_bar":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_qix_qix":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_foo_qix":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_qix_foo":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_bar_foo":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_bar_qix":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_foo_bar":4,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_qix_bar":4,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo":3,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_bar":3,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_qix":3,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo_bar":3,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo_qix":3,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_bar_qix":3,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo_bar_qix":3},"times":{"FooBarTest::test_is_result_foo":0.001,"FooBarTest::test_is_result_bar":0,"FooBarTest::test_is_result_foo_bar":0,"FooBarTest::test_is_result_qix":0.024,"FooBarQixTest::test_is_result_foo":0.001,"FooBarQixTest::test_is_result_bar":0,"FooBarQixTest::test_is_result_qix":0,"FooBarQixTest::test_is_result_foo_bar":0,"FooBarQixTest::test_is_result_foo_qix":0,"FooBarQixTest::test_is_result_bar_qix":0,"FooBarQixTest::test_is_result_foo_bar_qix":0,"FooBarQixOccurrencesTest::test_is_result_foo":0.001,"FooBarQixOccurrencesTest::test_is_result_qix":0,"FooBarQixOccurrencesTest::test_is_result_foo_qix":0,"FooBarQixOccurrencesTest::test_is_result_qix_foo":0,"FooBarQixOccurrencesTest::test_is_result_bar_foo":0,"FooBarQixOccurrencesTest::test_is_result_bar_qix":0,"FooBarQixCombinedTest::test_is_result_foo_foo":0.001,"FooBarQixCombinedTest::test_is_result_bar_bar":0,"FooBarQixCombinedTest::test_is_result_qix_qix":0,"FooBarQixCombinedTest::test_is_result_foo_qix":0,"FooBarQixCombinedTest::test_is_result_qix_foo":0,"FooBarQixCombinedTest::test_is_result_bar_foo":0,"FooBarQixCombinedTest::test_is_result_bar_qix":0,"FooBarQixCombinedTest::test_is_result_foo_bar":0,"FooBarQixCombinedTest::test_is_result_qix_bar":0,"FooBarQixMultiplesTest::test_is_result_foo":0.001,"FooBarQixMultiplesTest::test_is_result_bar":0,"FooBarQixMultiplesTest::test_is_result_qix":0,"FooBarQixMultiplesTest::test_is_result_foo_bar":0,"FooBarQixMultiplesTest::test_is_result_foo_qix":0,"FooBarQixMultiplesTest::test_is_result_bar_qix":0,"FooBarQixMultiplesTest::test_is_result_foo_bar_qix":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_foo_foo":0.001,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_bar_bar":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_qix_qix":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_foo_qix":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_qix_foo":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_bar_foo":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_bar_qix":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_foo_bar":0,"Tests\\FooBarQixTests\\FooBarQixCombinedTest::test_is_result_qix_bar":0,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_foo":0.001,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_inf":0,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_qix":0,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_inf_foo":0,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_qix_foo":0,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_inf_qix":0,"Tests\\InfQixFooTests\\InfQixFooMultiplesTest::test_is_result_inf_qix_foo":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_foo":0.001,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_qix":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_inf":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_foo_qix":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_qix_foo":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_inf_foo":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_foo_inf":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_inf_qix":0,"Tests\\InfQixFooTests\\InfQixFooOccurrencesTest::test_is_result_qix_inf":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_foo_foo":0.001,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_inf_inf":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_qix_qix":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_foo_qix":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_qix_foo":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_inf_foo":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_foo_inf":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_inf_qix":0,"Tests\\InfQixFooTests\\InfQixFooCombinedTest::test_is_result_qix_inf":0,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo":0.001,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_bar":0,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_qix":0,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo_bar":0,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo_qix":0,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_bar_qix":0,"Tests\\FooBarQixTests\\FooBarQixMultiplesTest::test_is_result_foo_bar_qix":0,"Tests\\FooBarQixTests\\FooBarQixOccurrencesTest::test_is_result_foo":0.001,"Tests\\FooBarQixTests\\FooBarQixOccurrencesTest::test_is_result_qix":0,"Tests\\FooBarQixTests\\FooBarQixOccurrencesTest::test_is_result_foo_qix":0,"Tests\\FooBarQixTests\\FooBarQixOccurrencesTest::test_is_result_qix_foo":0,"Tests\\FooBarQixTests\\FooBarQixOccurrencesTest::test_is_result_bar_foo":0,"Tests\\FooBarQixTests\\FooBarQixOccurrencesTest::test_is_result_bar_qix":0,"Tests\\InfQixFooTests\\InfQixFooMultipleOfEightTest::test_is_result_Inf_Inf_Inf":0.001,"Tests\\InfQixFooTests\\InfQixFooMultipleOfEightTest::test_is_result_Inf":0}}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This code Kata is an extended version of https://github.com/arolla/Craft_Your_Sk
3. Read task of this step
4. Start by creating Unit tests
5. Watch as tests fail
6. Create commit
6. Create comm
7. Write an implementation
8. Happily watch as all tests pass or modify tests
9. Refactor code (if needed)
Expand Down
10 changes: 10 additions & 0 deletions app/Combinations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

interface Combinations
{
public function __construct(string $highestNumber, string $midNumber, string $lowestNumber);

public function numberText(int $number): string;
}
48 changes: 48 additions & 0 deletions app/FooBarQix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App;

class FooBarQix implements Combinations
{
private string $lowestNumber;
private string $midNumber;
private string $highestNumber;

public function __construct(string $highestNumber, string $midNumber, string $lowestNumber)
{
$this->lowestNumber = $lowestNumber;
$this->midNumber = $midNumber;
$this->highestNumber = $highestNumber;
}

public function numberText(int $number): string
{
$occurrences = [];
$multiples = [];

$splitNumbers = str_split((string)$number);

foreach ($splitNumbers as $digit) {
if ($digit == 3) {
$occurrences[] = $this->lowestNumber;
}
if ($digit == 5) {
$occurrences[] = $this->midNumber;
}
if ($digit == 7) {
$occurrences[] = $this->highestNumber;
}
}
if ($number % 3 == 0) {
$multiples[] = $this->lowestNumber;
}
if ($number % 5 == 0) {
$multiples[] = $this->midNumber;
}
if ($number % 7 == 0) {
$multiples[] = $this->highestNumber;
}

return implode("", $occurrences) . implode(", ", $multiples);
}
}
54 changes: 54 additions & 0 deletions app/InfQixFoo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App;

class InfQixFoo implements Combinations
{
private string $highestNumber;
private string $midNumber;
private string $lowestNumber;

public function __construct(string $highestNumber, string $midNumber, string $lowestNumber)
{
$this->highestNumber = $highestNumber;
$this->midNumber = $midNumber;
$this->lowestNumber = $lowestNumber;
}

public function numberText(int $number): string
{
$occurrences = [];
$multiples = [];

$splitNumbers = str_split((string)$number);

foreach ($splitNumbers as $digit) {
if ($digit == 3) {
$occurrences[] = $this->lowestNumber;
}
if ($digit == 7) {
$occurrences[] = $this->midNumber;
}
if ($digit == 8) {
$occurrences[] = $this->highestNumber;
}
}
if ($number % 8 == 0) {
$multiples[] = $this->highestNumber;
}
if ($number % 7 == 0) {
$multiples[] = $this->midNumber;
}
if ($number % 3 == 0) {
$multiples[] = $this->lowestNumber;
}

$multipleOccurrences = implode("", $occurrences) . implode("; ", $multiples);

if (array_sum($splitNumbers) % 8 == 0) {
return $multipleOccurrences . $this->highestNumber;
} else {
return $multipleOccurrences;
}
}
}
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Tests\\": "tests/"
}
},
"require": {
"ext-readline": "*"
}
}
Loading