This commit is contained in:
Kavalar 2024-05-17 14:16:29 +03:00
commit fea8580204
8 changed files with 140 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

24
index.php Normal file
View 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
View 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
View 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
View 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
View 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>";
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace src\interfaces;
interface TypeInterface
{
}

13
src/traits/Jumping.php Normal file
View 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>";
}
}