first
This commit is contained in:
commit
fea8580204
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
24
index.php
Normal file
24
index.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
require_once "src/Animal.php";
|
||||
require_once "src/traits/Jumping.php";
|
||||
require_once "src/Cat.php";
|
||||
require_once "src/Dog.php";
|
||||
require_once "src/Cow.php";
|
||||
|
||||
$cat = new \src\Cat();
|
||||
$dog = new \src\Dog();
|
||||
$cow = new \src\Cow();
|
||||
|
||||
$dog->makeSound();
|
||||
$cat->makeSound();
|
||||
$cow->makeSound();
|
||||
|
||||
$dog->makeJump();
|
||||
$cat->makeJump();
|
||||
|
||||
echo "<pre>";
|
||||
print_r($cat);
|
||||
|
||||
$cat->meow();
|
||||
$dog->woof();
|
30
src/Animal.php
Normal file
30
src/Animal.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace src;
|
||||
|
||||
abstract class Animal
|
||||
{
|
||||
public string $type = "animal";
|
||||
|
||||
public $eyes;
|
||||
|
||||
public int $paws = 0;
|
||||
|
||||
public int $heart = 0;
|
||||
|
||||
public function walk(): void
|
||||
{
|
||||
$this->paws++;
|
||||
}
|
||||
|
||||
abstract public function makeSound(): void;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function beating(): void
|
||||
{
|
||||
$this->heart++;
|
||||
}
|
||||
|
||||
}
|
27
src/Cat.php
Normal file
27
src/Cat.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace src;
|
||||
|
||||
use src\traits\Jumping;
|
||||
|
||||
/**
|
||||
* @property $eyes
|
||||
* @property $paws
|
||||
* @property $heart
|
||||
*/
|
||||
class Cat extends Animal
|
||||
{
|
||||
use Jumping;
|
||||
|
||||
public string $type = "CAT";
|
||||
public function makeSound(): void
|
||||
{
|
||||
echo $this->type . " - shipe shipe shipe shipe shipe shipe shipe shipe shipe shipe shipe <br>";
|
||||
}
|
||||
|
||||
public function meow()
|
||||
{
|
||||
echo $this->type . " - meow meow meow meow meow meow meow meow meow meow meow meow meow meow <br>";
|
||||
}
|
||||
|
||||
}
|
13
src/Cow.php
Normal file
13
src/Cow.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace src;
|
||||
|
||||
class Cow extends Animal
|
||||
{
|
||||
public string $type = "COW";
|
||||
|
||||
public function makeSound(): void
|
||||
{
|
||||
echo $this->type . " - mu mu mu mu mu mu mu mu mu mu mu mu mu mu mu mu mu <br>";
|
||||
}
|
||||
}
|
23
src/Dog.php
Normal file
23
src/Dog.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace src;
|
||||
|
||||
use src\traits\Jumping;
|
||||
|
||||
class Dog extends Animal
|
||||
{
|
||||
use Jumping;
|
||||
|
||||
public string $type = "DOG";
|
||||
|
||||
public function makeSound(): void
|
||||
{
|
||||
echo $this->type . " - growling growling growling growling growling growling growling growling <br>";
|
||||
}
|
||||
|
||||
public function woof()
|
||||
{
|
||||
echo $this->type . " - woof woof woof woof woof woof woof woof woof woof woof woof woof woof <br>";
|
||||
}
|
||||
|
||||
}
|
9
src/interfaces/TypeInterface.php
Normal file
9
src/interfaces/TypeInterface.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace src\interfaces;
|
||||
|
||||
interface TypeInterface
|
||||
{
|
||||
|
||||
|
||||
}
|
13
src/traits/Jumping.php
Normal file
13
src/traits/Jumping.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace src\traits;
|
||||
|
||||
trait Jumping
|
||||
{
|
||||
|
||||
public function makeJump(): void
|
||||
{
|
||||
echo $this->type . " - jump jump jump jump jump jump jump jump jump jump <br>";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user