Skip to content

Commit

Permalink
feat: add address based functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gere-lajos committed Apr 20, 2024
1 parent 4624b6d commit df0e73a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ $fullMaleName = $meow->fullMaleName(); // "Toby Tabbyfield"
$fullFemaleName = $meow->fullFemaleName(); // "Luna Furbridge"
```

### Generate addresses
```php
$address = $meow->address(); // " Slinkyside, Clawchester, Tabby Crossroad 228, 4725"
$country = $meow->country(); // "Purrch Republic"
$city = $meow->city(); // "Whisperwind"
$street = $meow->street(); // "Meow Highway"
$postcode = $meow->postcode(); // "4725"
$buildingNumber = $meow->buildingNumber(); // "228"
```

### Generate miscellaneous items
```php
$email = $meow->email(); // "[email protected]"
Expand Down
40 changes: 40 additions & 0 deletions src/Meow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace GereLajos\MeowMaker;

use GereLajos\MeowMaker\Enums\AddressType;
use GereLajos\MeowMaker\Enums\MiscType;
use GereLajos\MeowMaker\Enums\NameType;
use GereLajos\MeowMaker\Enums\WordType;
Expand Down Expand Up @@ -114,6 +115,45 @@ public function emails(int $count = 1): Items
return Randomizer::pickToArray(fn () => $this->email(), $count);
}

public function country(): Item
{
return Randomizer::pick($this->dictionary->address(AddressType::COUNTRY));
}

public function city(): Item
{
return Randomizer::pick($this->dictionary->address(AddressType::CITY));
}

public function street(): Item
{
$street = Randomizer::pick($this->dictionary->address(AddressType::STREET));
$street_suffix = Randomizer::pick($this->dictionary->address(AddressType::STREET_SUFFIX));

return new Item("$street $street_suffix");
}

public function buildingNumber(): Item
{
return new Item((string) mt_rand(1, 999));
}

public function postcode(): Item
{
return new Item((string) mt_rand(1000, 9999));
}

public function address(): Item
{
$country = $this->country();
$city = $this->city();
$street = $this->street();
$buildingNumber = $this->buildingNumber();
$postcode = $this->postcode();

return new Item("$country, $city, $street $buildingNumber, $postcode");
}

public function word(): Item
{
return Randomizer::pick($this->dictionary->words());
Expand Down
8 changes: 8 additions & 0 deletions src/playground.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
echo 'More names: ' . implode(', ', $meow->names(5)->toArray()) . PHP_EOL;
echo $separator . PHP_EOL;

// Generate address
echo 'An address: ' . $meow->address() . PHP_EOL;
echo 'A country: ' . $meow->country() . PHP_EOL;
echo 'A city: ' . $meow->city() . PHP_EOL;
echo 'A street: ' . $meow->street() . PHP_EOL;
echo 'A postcode: ' . $meow->postcode() . PHP_EOL;
echo 'A building number: ' . $meow->buildingNumber() . PHP_EOL;

// Generate misc items
echo 'An email: ' . $meow->email() . PHP_EOL;
echo 'More emails: ' . implode(', ', $meow->emails(3)->toArray()) . PHP_EOL;
Expand Down
51 changes: 51 additions & 0 deletions tests/AddressTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace GereLajos\MeowMaker\Tests;

use GereLajos\MeowMaker\Enums\MiscType;
use GereLajos\MeowMaker\Meow;
use GereLajos\MeowMaker\Structures\Item;
use GereLajos\MeowMaker\Structures\Items;
use PHPUnit\Framework\TestCase;

class AddressTest extends TestCase
{
private Meow $meow;

public function setUp(): void
{
$this->meow = new Meow();
}

public function testItCanGenerateAddress(): void
{
$this->assertInstanceOf(Item::class, $this->meow->address());
}

public function testItCanGeneratePostcode(): void
{
$this->assertInstanceOf(Item::class, $this->meow->postcode());
}

public function testItCanGenerateStreet(): void
{
$this->assertInstanceOf(Item::class, $this->meow->street());
}

public function testItCanGenerateCity(): void
{
$this->assertInstanceOf(Item::class, $this->meow->city());
}

public function testItCanGenerateCountry(): void
{
$this->assertInstanceOf(Item::class, $this->meow->country());
}

public function testItCanGenerateBuildingNumber(): void
{
$this->assertInstanceOf(Item::class, $this->meow->buildingNumber());
}
}

0 comments on commit df0e73a

Please sign in to comment.