Skip to content

Instantly share code, notes, and snippets.

@evolic
Created October 8, 2016 20:02
Show Gist options
  • Select an option

  • Save evolic/d84088de09713d22191b7485906cd798 to your computer and use it in GitHub Desktop.

Select an option

Save evolic/d84088de09713d22191b7485906cd798 to your computer and use it in GitHub Desktop.
Detrmining if person is Polish man or woman based on his/her name
<?php
namespace Persons;
class Person
{
CONST MAN = 'man';
CONST WOMAN = 'woman';
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $gender;
public function __construct($name)
{
$this->name = $name;
$this->gender = $this->isMan($name) ? self::MAN : self::WOMAN;
}
protected function isMan($name)
{
return substr($name, -1, 1) !== 'a';
}
private function setGender($gender)
{
$this->gender = $gender;
return $this;
}
public function __toString()
{
return $this->name . ', ' . $this->gender;
}
}
$person1 = new Person('Karol');
echo $person1 . PHP_EOL;
$person2 = new Person('Anna');
echo $person2 . PHP_EOL;
$person3 = new Person('Tomasz');
echo $person3 . PHP_EOL;
$person4 = new Person('Kaja');
echo $person4 . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment