Migrate all code
This commit is contained in:
commit
99f25729bd
53
cli.php
Normal file
53
cli.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\Animal\Animal;
|
||||
use Keedosn\UnityGroupTest\Zoo\Meal\Corn;
|
||||
use Keedosn\UnityGroupTest\Zoo\Meal\Leaf;
|
||||
use Keedosn\UnityGroupTest\Zoo\Meal\Steak;
|
||||
use Keedosn\UnityGroupTest\Zoo\Species\Elephant;
|
||||
use Keedosn\UnityGroupTest\Zoo\Species\Fox;
|
||||
use Keedosn\UnityGroupTest\Zoo\Species\SnowLeopard;
|
||||
use Keedosn\UnityGroupTest\Zoo\Zoo;
|
||||
|
||||
$mealCorn = new Corn();
|
||||
$mealLeaf = new Leaf();
|
||||
$mealSteak = new Steak();
|
||||
|
||||
$zoo = new Zoo();
|
||||
|
||||
$fox = new Animal('Lisek', new Fox());
|
||||
$zoo->add($fox);
|
||||
|
||||
echo $fox . PHP_EOL;
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $fox->getName(), $mealCorn->getName(), $fox->fed($mealCorn) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $fox->getName(), $mealLeaf->getName(), $fox->fed($mealLeaf) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $fox->getName(), $mealSteak->getName(), $fox->fed($mealSteak) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Czy zwierze ma futro? %s' . PHP_EOL, ($fox->hasFur() ? 'Tak' : 'Nie'));
|
||||
$fox->clearFur();
|
||||
echo PHP_EOL;
|
||||
|
||||
$elephant = new Animal('Słonik', new Elephant());
|
||||
$zoo->add($elephant);
|
||||
|
||||
echo $elephant . PHP_EOL;
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $elephant->getName(), $mealCorn->getName(), $elephant->fed($mealCorn) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $elephant->getName(), $mealLeaf->getName(), $elephant->fed($mealLeaf) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $elephant->getName(), $mealSteak->getName(), $elephant->fed($mealSteak) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Czy zwierze ma futro? %s' . PHP_EOL, ($elephant->hasFur() ? 'Tak' : 'Nie'));
|
||||
$elephant->clearFur();
|
||||
echo PHP_EOL;
|
||||
|
||||
$sl = new Animal('Leopard', new SnowLeopard());
|
||||
$zoo->add($sl);
|
||||
|
||||
echo $sl . PHP_EOL;
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $sl->getName(), $mealCorn->getName(), $sl->fed($mealCorn) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $sl->getName(), $mealLeaf->getName(), $sl->fed($mealLeaf) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Karmie %s jedzeniem: %s - %s' . PHP_EOL, $sl->getName(), $mealSteak->getName(), $sl->fed($mealSteak) ? 'Zjedzone' : 'Odrzucone');
|
||||
printf('Czy zwierze ma futro? %s' . PHP_EOL, ($sl->hasFur() ? 'Tak' : 'Nie'));
|
||||
$sl->clearFur();
|
||||
echo PHP_EOL;
|
||||
|
||||
echo sprintf('W Zoo przebywa obecnie: %d zwierząt' . PHP_EOL, $zoo->count());
|
17
composer.json
Normal file
17
composer.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "keedosn/unity-group-test",
|
||||
"description": "PHP Test Task",
|
||||
"type": "project",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Keedosn\\UnityGroupTest\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Piotr Biernat",
|
||||
"email": "keedosn@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
}
|
165
db-dump.sql
Normal file
165
db-dump.sql
Normal file
@ -0,0 +1,165 @@
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.2 (Debian 16.2-1.pgdg120+2)
|
||||
-- Dumped by pg_dump version 16.2 (Debian 16.2-1.pgdg120+2)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: authors; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.authors (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
first_name character varying NOT NULL,
|
||||
last_name character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.authors OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: average_grades; Type: VIEW; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE VIEW public.average_grades AS
|
||||
SELECT
|
||||
NULL::character varying(255) AS title,
|
||||
NULL::bigint AS reviews_count,
|
||||
NULL::numeric AS avg_grade;
|
||||
|
||||
|
||||
ALTER VIEW public.average_grades OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: VIEW average_grades; Type: COMMENT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COMMENT ON VIEW public.average_grades IS 'widok zawierający 5-ciu autorów, których średnia
|
||||
ocen wszystkich książek jest najwyższa.';
|
||||
|
||||
|
||||
--
|
||||
-- Name: books; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.books (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
author_id uuid NOT NULL,
|
||||
title character varying(255) NOT NULL,
|
||||
published_year integer NOT NULL,
|
||||
isbn character varying(20) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.books OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: reviews; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.reviews (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
book_id uuid NOT NULL,
|
||||
grade smallint NOT NULL,
|
||||
review text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.reviews OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Data for Name: authors; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.authors (id, first_name, last_name) VALUES ('a842544f-2f2d-4fdb-82c0-90c84902c996', 'Best', 'Seller');
|
||||
INSERT INTO public.authors (id, first_name, last_name) VALUES ('ea4b242d-4fb9-4b7e-9301-3f5489759eb8', 'Yoko', 'Ono');
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: books; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.books (id, author_id, title, published_year, isbn) VALUES ('13564239-b83c-4896-88cb-f92b312438ab', 'a842544f-2f2d-4fdb-82c0-90c84902c996', 'Rozwiązanie tajemnicy Bażanta', 2003, '15487-634-756-123');
|
||||
INSERT INTO public.books (id, author_id, title, published_year, isbn) VALUES ('752f58d2-604a-466e-8957-ced8c256a0c6', 'a842544f-2f2d-4fdb-82c0-90c84902c996', 'Tajemnica zaginionego Bażanta', 2001, '12346-543-123-162');
|
||||
INSERT INTO public.books (id, author_id, title, published_year, isbn) VALUES ('b9fc879e-ba41-4d89-819d-7bb928eab557', 'ea4b242d-4fb9-4b7e-9301-3f5489759eb8', 'Autobiografia Yoko Ono', 1999, '12345-567-789-123');
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: reviews; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('ef2355d8-3277-440b-8344-7fff3ea72a8a', '13564239-b83c-4896-88cb-f92b312438ab', 9, 'Mam nadzieje na kolejną część');
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('bdd1ecaa-0fa7-4546-b9fd-e1138c5d52a6', '752f58d2-604a-466e-8957-ced8c256a0c6', 4, 'Dobra literatura');
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('6db5ef53-751b-4034-b61c-8c31b6a1af80', '752f58d2-604a-466e-8957-ced8c256a0c6', 6, 'Niezła ksiązka');
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('f28488b5-24db-4e64-8455-aa30ea1f1c10', '752f58d2-604a-466e-8957-ced8c256a0c6', 7, 'Spoko');
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('cb0a3d30-fd8f-45a3-8c9f-f8763fa332eb', 'b9fc879e-ba41-4d89-819d-7bb928eab557', 6, 'Spoko ksiązka');
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('bccfa802-c020-450e-9b76-376251c15de1', '13564239-b83c-4896-88cb-f92b312438ab', 7, 'OK');
|
||||
INSERT INTO public.reviews (id, book_id, grade, review) VALUES ('9a23d2d8-988a-49f9-888e-4e68233c456b', '13564239-b83c-4896-88cb-f92b312438ab', 8, 'Bardzo dobra. Lepsza niż poprzednia.');
|
||||
|
||||
|
||||
--
|
||||
-- Name: authors authors_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.authors
|
||||
ADD CONSTRAINT authors_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: books books_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.books
|
||||
ADD CONSTRAINT books_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: reviews reviews_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.reviews
|
||||
ADD CONSTRAINT reviews_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: average_grades _RETURN; Type: RULE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE OR REPLACE VIEW public.average_grades AS
|
||||
SELECT b.title,
|
||||
count(DISTINCT r.id) AS reviews_count,
|
||||
avg(r.grade) AS avg_grade
|
||||
FROM (public.books b
|
||||
JOIN public.reviews r ON ((r.book_id = b.id)))
|
||||
GROUP BY b.id
|
||||
ORDER BY (avg(r.grade)) DESC
|
||||
LIMIT 5;
|
||||
|
||||
|
||||
--
|
||||
-- Name: reviews reviews_book_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.reviews
|
||||
ADD CONSTRAINT reviews_book_id_fkey FOREIGN KEY (book_id) REFERENCES public.books(id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
14
queries.sql
Normal file
14
queries.sql
Normal file
@ -0,0 +1,14 @@
|
||||
-- Pobieranie autorów wraz z ilością książek:
|
||||
SELECT a.first_name, a.last_name, COUNT(DISTINCT b.id) AS writed_books
|
||||
FROM public.authors a
|
||||
JOIN public.books b ON b.author_id = a.id
|
||||
GROUP BY a.id
|
||||
|
||||
-- Pobieranie książek wraz z ilością recenzji:
|
||||
SELECT b.title, COUNT(DISTINCT r.id) AS reviews_count, AVG(r.grade) AS avg_grade
|
||||
FROM public.books b
|
||||
JOIN public.reviews r ON r.book_id = b.id
|
||||
GROUP BY b.id
|
||||
|
||||
-- Pobranie danych za pomoca widoku:
|
||||
SELECT * FROM public.average_grades
|
56
src/Zoo/Animal/Animal.php
Normal file
56
src/Zoo/Animal/Animal.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Animal;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\Meal\Meal;
|
||||
use Keedosn\UnityGroupTest\Zoo\Species\Species;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
|
||||
class Animal
|
||||
{
|
||||
private $name = '';
|
||||
|
||||
private Species $species;
|
||||
|
||||
function __construct(string $name, Species $species)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->species = $species;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('%s %s', $this->species->getName(), $this->name);
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function fed(Meal $meal): bool
|
||||
{
|
||||
if ($this->species->getFoodType()->getType() === FoodType::TYPE_OMNIVOROUS) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->species->getFoodType()->getType() === $meal->getType()->getType()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return $this->species->hasFur();
|
||||
}
|
||||
|
||||
public function clearFur(): void
|
||||
{
|
||||
if ($this->hasFur()) {
|
||||
$this->species->clearFur();
|
||||
echo 'Futro zostało wyczyszczone' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
10
src/Zoo/FoodType/Carnivorous.php
Normal file
10
src/Zoo/FoodType/Carnivorous.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\FoodType;
|
||||
|
||||
class Carnivorous extends FoodType
|
||||
{
|
||||
protected string $name = 'Mięsożerny';
|
||||
|
||||
protected string $type = FoodType::TYPE_CARNIVOROUS;
|
||||
}
|
26
src/Zoo/FoodType/FoodType.php
Normal file
26
src/Zoo/FoodType/FoodType.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\FoodType;
|
||||
|
||||
abstract class FoodType
|
||||
{
|
||||
public const TYPE_CARNIVOROUS = 'carnivorous';
|
||||
|
||||
public const TYPE_HERBIVOROUS = 'herbivorous';
|
||||
|
||||
public const TYPE_OMNIVOROUS = 'omnivorous';
|
||||
|
||||
protected string $name;
|
||||
|
||||
protected string $type;
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
10
src/Zoo/FoodType/Herbivorous.php
Normal file
10
src/Zoo/FoodType/Herbivorous.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\FoodType;
|
||||
|
||||
class Herbivorous extends FoodType
|
||||
{
|
||||
protected string $name = 'Roślinożerny';
|
||||
|
||||
protected string $type = FoodType::TYPE_HERBIVOROUS;
|
||||
}
|
10
src/Zoo/FoodType/Omnivorous.php
Normal file
10
src/Zoo/FoodType/Omnivorous.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\FoodType;
|
||||
|
||||
class Omnivorous extends FoodType
|
||||
{
|
||||
protected string $name = 'Wszystkożerny';
|
||||
|
||||
protected string $type = FoodType::TYPE_OMNIVOROUS;
|
||||
}
|
19
src/Zoo/Meal/Corn.php
Normal file
19
src/Zoo/Meal/Corn.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Meal;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Herbivorous;
|
||||
|
||||
class Corn extends Meal
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Kukurydzna';
|
||||
}
|
||||
|
||||
public function getType(): FoodType
|
||||
{
|
||||
return new Herbivorous();
|
||||
}
|
||||
}
|
19
src/Zoo/Meal/Leaf.php
Normal file
19
src/Zoo/Meal/Leaf.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Meal;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Herbivorous;
|
||||
|
||||
class Leaf extends Meal
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Liście';
|
||||
}
|
||||
|
||||
public function getType(): FoodType
|
||||
{
|
||||
return new Herbivorous();
|
||||
}
|
||||
}
|
12
src/Zoo/Meal/Meal.php
Normal file
12
src/Zoo/Meal/Meal.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Meal;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
|
||||
abstract class Meal
|
||||
{
|
||||
abstract public function getType(): FoodType;
|
||||
|
||||
abstract public function getName(): string;
|
||||
}
|
20
src/Zoo/Meal/Steak.php
Normal file
20
src/Zoo/Meal/Steak.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Meal;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Carnivorous;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
|
||||
class Steak extends Meal
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Stek wołowy';
|
||||
}
|
||||
|
||||
|
||||
public function getType(): FoodType
|
||||
{
|
||||
return new Carnivorous();
|
||||
}
|
||||
}
|
31
src/Zoo/Species/Elephant.php
Normal file
31
src/Zoo/Species/Elephant.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Herbivorous;
|
||||
|
||||
class Elephant extends Species
|
||||
{
|
||||
protected string $name = 'Słoń';
|
||||
|
||||
public function getFoodType(): FoodType
|
||||
{
|
||||
return new Herbivorous();
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function clearFur(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSound(): string
|
||||
{
|
||||
return 'Trumpet';
|
||||
}
|
||||
}
|
33
src/Zoo/Species/Fox.php
Normal file
33
src/Zoo/Species/Fox.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Omnivorous;
|
||||
|
||||
class Fox extends Species
|
||||
{
|
||||
protected string $name = 'Lis';
|
||||
|
||||
public function getFoodType(): FoodType
|
||||
{
|
||||
return new Omnivorous();
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearFur(): bool
|
||||
{
|
||||
echo 'Indywidualny sposób mycia lisa...';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSound(): string
|
||||
{
|
||||
return 'Yip';
|
||||
}
|
||||
}
|
33
src/Zoo/Species/Rabbit.php
Normal file
33
src/Zoo/Species/Rabbit.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Herbivorous;
|
||||
|
||||
class Rabbit extends Species
|
||||
{
|
||||
protected string $name = 'Królik';
|
||||
|
||||
public function getFoodType(): FoodType
|
||||
{
|
||||
return new Herbivorous();
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearFur(): bool
|
||||
{
|
||||
echo 'Indywidualny sposób mycia królika...';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSound(): string
|
||||
{
|
||||
return 'Squeak';
|
||||
}
|
||||
}
|
31
src/Zoo/Species/Rhino.php
Normal file
31
src/Zoo/Species/Rhino.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Herbivorous;
|
||||
|
||||
class Rhino extends Species
|
||||
{
|
||||
protected string $name = 'Nosorożec';
|
||||
|
||||
public function getFoodType(): FoodType
|
||||
{
|
||||
return new Herbivorous();
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function clearFur(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSound(): string
|
||||
{
|
||||
return 'Snort';
|
||||
}
|
||||
}
|
33
src/Zoo/Species/SnowLeopard.php
Normal file
33
src/Zoo/Species/SnowLeopard.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Carnivorous;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
|
||||
class SnowLeopard extends Species
|
||||
{
|
||||
protected string $name = 'Ibris śnieżny';
|
||||
|
||||
public function getFoodType(): FoodType
|
||||
{
|
||||
return new Carnivorous();
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearFur(): bool
|
||||
{
|
||||
echo 'Indywidualny sposób mycia ibrysa syberyjskiego...';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSound(): string
|
||||
{
|
||||
return 'Growl';
|
||||
}
|
||||
}
|
25
src/Zoo/Species/Species.php
Normal file
25
src/Zoo/Species/Species.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
|
||||
abstract class Species
|
||||
{
|
||||
protected string $name = '';
|
||||
|
||||
private FoodType $foodType;
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public abstract function hasFur(): bool;
|
||||
|
||||
public abstract function clearFur(): bool;
|
||||
|
||||
public abstract function getSound(): string;
|
||||
|
||||
public abstract function getFoodType(): FoodType;
|
||||
}
|
31
src/Zoo/Species/Tiger.php
Normal file
31
src/Zoo/Species/Tiger.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo\Species;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\Carnivorous;
|
||||
use Keedosn\UnityGroupTest\Zoo\FoodType\FoodType;
|
||||
|
||||
class Tiger extends Species
|
||||
{
|
||||
protected string $name = 'Tygrys';
|
||||
|
||||
public function getFoodType(): FoodType
|
||||
{
|
||||
return new Carnivorous();
|
||||
}
|
||||
|
||||
public function hasFur(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearFur(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSound(): string
|
||||
{
|
||||
return 'Roar';
|
||||
}
|
||||
}
|
20
src/Zoo/Zoo.php
Normal file
20
src/Zoo/Zoo.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Keedosn\UnityGroupTest\Zoo;
|
||||
|
||||
use Keedosn\UnityGroupTest\Zoo\Animal\Animal;
|
||||
|
||||
class Zoo
|
||||
{
|
||||
private array $animals = [];
|
||||
|
||||
public function add(Animal $animal)
|
||||
{
|
||||
$this->animals[] = $animal;
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->animals);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user