{"id":21337000,"url":"https://github.com/vsvietkov/sigma-internship-pet-project","last_synced_at":"2026-04-12T09:02:58.663Z","repository":{"id":40249946,"uuid":"443845899","full_name":"vsvietkov/sigma-internship-pet-project","owner":"vsvietkov","description":"A project to demonstrate my knowledge and ability to use Object-Oriented Design on practice.","archived":false,"fork":false,"pushed_at":"2022-05-18T06:58:05.000Z","size":469,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T02:14:20.095Z","etag":null,"topics":["docker","factory-pattern","laravel","ood","oop","reactjs","solid"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vsvietkov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-02T18:54:30.000Z","updated_at":"2023-06-05T11:10:26.000Z","dependencies_parsed_at":"2022-08-24T14:33:53.067Z","dependency_job_id":null,"html_url":"https://github.com/vsvietkov/sigma-internship-pet-project","commit_stats":null,"previous_names":["vsvietkov/sigma-internship-pet-project"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vsvietkov/sigma-internship-pet-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsvietkov%2Fsigma-internship-pet-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsvietkov%2Fsigma-internship-pet-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsvietkov%2Fsigma-internship-pet-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsvietkov%2Fsigma-internship-pet-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsvietkov","download_url":"https://codeload.github.com/vsvietkov/sigma-internship-pet-project/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsvietkov%2Fsigma-internship-pet-project/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265710963,"owners_count":23815442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","factory-pattern","laravel","ood","oop","reactjs","solid"],"created_at":"2024-11-21T23:56:49.050Z","updated_at":"2026-04-12T09:02:58.633Z","avatar_url":"https://github.com/vsvietkov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## \u003cp align=\"center\"\u003eSigma Internship Pet-Project\u003c/p\u003e\n\nThis is a small project the main aim of which is to demonstrate my knowledge and ability to use *Object-Oriented Design* on practice.\n\nA program provides a simple calculator for basic geometry figures like Circle, Sphere etc. You need to enter at least one shape characteristic to get the calculation results.\n\n![Screenshot from 2022-01-14 11-14-13](https://user-images.githubusercontent.com/95583010/149490178-23b75c1a-be93-467a-9e33-089077d3f2c3.png)\n\n### Installation\n\n- Ensure that you are in the root directory of a project\n- Run `make docker-build`\n- Run `make npm-install`\n- Run `make composer-install`\n- Run `make start`\n- Now you can check out http://localhost:3000\n\n## \u003cp align=\"center\"\u003eSOLID\u003c/p\u003e\n### Single-responsibility\nIt is very problematic to implement all ways of calculations output for every figure (consider that in future there will\nbe more than one option), so the `app/Components/CalculationsOutputter` class was created with a single aim - to output\nthe calculations:\n```php\nclass CalculationsOutputter\n{\n    /**\n     * @var BaseShape\n     */\n    private BaseShape $shape;\n\n    public function __construct(BaseShape $shape)\n    {\n        $this-\u003eshape = $shape;\n    }\n\n    /**\n     * Get the calculated results\n     * \n     * @return array\n     */\n    public function output()\n    {\n        return $this-\u003eshape-\u003eserialize();\n    }\n}\n```\n### Open-closed\nEvery shape implements `calculateAllAttributes` and `serialize` methods which can be reused in future by many classes\nwithout the necessity to check the figure type to perform calculations and output. The use of `serialize` method was\nalready shown in the \"Single responsibility\" section.\n### Interface Segregation\nGeometrical figures can be two-dimensional and three-dimensional and thus have different characteristics. So, it will be\nconvenient to use different interfaces for such shapes:\n```php\ninterface Shape2DInterface\n{\n    public function calculatePerimeter(): ?float;\n}\n\ninterface Shape3DInterface\n{\n    public function calculateVolume(): ?float;\n}\n```\n### Dependency Inversion\n`app/Components/CalculationOutputter` class does not care what shape we passed into it as long as all classes inherited\nfrom `app/Components/BaseShape` have all necessary methods.\n```php\nclass CalculationsOutputter\n{\n    /**\n     * @var BaseShape\n     */\n    private BaseShape $shape;\n\n    public function __construct(BaseShape $shape)\n    {\n        $this-\u003eshape = $shape;\n    }\n    ...\n}\n ```\n## \u003cp align=\"center\"\u003eOOP principles\u003c/p\u003e\n### Encapsulation\nEach figure has its characteristics as `private` and it is required to use getters to access them:\n```php\n /**\n  * @var float|null\n  */\n private ?float $side;\n\n /**\n  * @var float|null\n  */\n private ?float $diagonal;\n\n /**\n  * @return float|null\n  */\n public function getSide(): ?float\n {\n     return $this-\u003eside;\n }\n\n /**\n  * @return float|null\n  */\n public function getDiagonal(): ?float\n {\n     return $this-\u003ediagonal;\n }\n```\n### Inheritance\nTaking into account that every custom rule has the same error message format, an abstract class that implements this\nmessage is used:\n```php\nabstract class BaseRule implements Rule\n{\n    /**\n     * @var string\n     */\n    protected string $relatedValue;\n\n    /**\n     * Get the validation error message.\n     *\n     * @return string\n     */\n    public function message(): string\n    {\n        return \"A value does not coincide with given $this-\u003erelatedValue.\";\n    }\n}\n```\nIn a rule, we set the related characteristic name and if it fails the check, a message will have this characteristic's\nname:\n```php\nclass SquareAreaRule extends BaseRule\n{\n    /**\n     * Determine if the validation rule passes.\n     *\n     * @param  string $attribute\n     * @param  mixed  $value\n     * @return bool\n     */\n    public function passes($attribute, $value): bool\n    {\n        $square = null;\n        if (request()-\u003einput('side')) {\n            $this-\u003erelatedValue = 'side';\n            $square = new Square(floatval(request()-\u003einput('side')));\n        } ...\n        \n        return is_null($square) || floatval($value) === $square-\u003ecalculateArea();\n    }\n}\n```\n### Polymorphism\nEvery shape class is inherited from the `app/Components/BaseShape` class and has to implement the `serialize` method,\nwhich simply returns the shape's characteristics as an array:\n```php\nabstract class BaseShape\n{\n    /**\n     * Get an array of all properties of the shape\n     *\n     * @return array\n     */\n    abstract public function serialize(): array;\n}\n\nclass Square extends BaseShape implements ShapeInterface, Shape2DInterface\n{\n    ...\n    \n    /**\n     * @return array\n     */\n    public function serialize(): array\n    {\n        return [\n            'side'      =\u003e $this-\u003eside,\n            'diagonal'  =\u003e $this-\u003ediagonal,\n            'area'      =\u003e $this-\u003earea,\n            'perimeter' =\u003e $this-\u003eperimeter,\n        ];\n    }\n}\n```\n## \u003cp align=\"center\"\u003eFactory Pattern\u003c/p\u003e\nTaking into account that an application can have lots of geometrical figures, it can be problematic to write new\ngenerator lines for each of them. So, `app/Components/ShapeFactory` class that follows a Factory Pattern was created.\n\n```php\n /**\n  * @param  string $shapeName\n  * @return BaseShape\n  * @throws NoSuchShapeException\n  */\n public function make(string $shapeName): BaseShape\n {\n     $className = $this-\u003enamespace . \"\\\\$shapeName\";\n\n     if (class_exists($className)) {\n         return new $className();\n     }\n\n     throw new NoSuchShapeException;\n }\n```\n\nThe above function takes as an argument the name of figure class and tries to create it. If there is no such class in\nthe defined namespace, a custom exception will be thrown. This allows to freely expand the project and catch errors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsvietkov%2Fsigma-internship-pet-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsvietkov%2Fsigma-internship-pet-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsvietkov%2Fsigma-internship-pet-project/lists"}