Skip to content
Merged

Wip #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-----

# Singleton | [API](https://github.com/Jagepard/PhpDesignPatterns-Singleton/blob/master/docs.md "Documentation API")
```php run``` Запустить исполнение шаблона в терминале

Одиночка
```php run``` execute in terminal

![Singleton](https://github.com/Jagepard/PhpDesignPatterns-Singleton/blob/master/UML.png)
6 changes: 2 additions & 4 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

### Class: \AntiPatterns\Singleton\Singleton

> Class Singleton

| Visibility | Function |
|:-----------|:---------|
| public | <strong>__clone()</strong> : <em>void</em> |
| public | <strong>__construct()</strong> : <em>void</em> |
| public | <strong>__construct()</strong> : <em>void</em><br /><em>SingletonTrait constructor.</em> |
| public | <strong>__sleep()</strong> : <em>void</em> |
| public | <strong>__wakeup()</strong> : <em>void</em> |
| public static | <strong>getInstance()</strong> : <em>mixed</em> |
| public static | <strong>getInstance()</strong> : <em>\AntiPatterns\Singleton\self</em> |

51 changes: 46 additions & 5 deletions src/Singleton.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
<?php

declare(strict_types=1);

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @license https://mit-license.org/ MIT
* @author : Jagepard <jagepard@yandex.ru>
* @license https://mit-license.org/ MIT
*/

namespace AntiPatterns\Singleton;

final class Singleton
{
use SingletonTrait;
/**
* @var self
*/
private static $instance;

/**
* @return self
*/
public static function getInstance(): self
{
if (!self::$instance instanceof self) {
self::$instance = new self();
}

return self::$instance;
}

/**
* SingletonTrait constructor.
*/
public function __construct()
{
}

/**
* @codeCoverageIgnore
*/
public function __sleep()
{
}

/**
* @codeCoverageIgnore
*/
public function __wakeup()
{
}

/**
* @codeCoverageIgnore
*/
public function __clone()
{
}
}
58 changes: 0 additions & 58 deletions src/SingletonTrait.php

This file was deleted.

6 changes: 2 additions & 4 deletions tests/SingletonTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @license https://mit-license.org/ MIT
* @author : Jagepard <jagepard@yandex.ru>
* @license https://mit-license.org/ MIT
*/

namespace AntiPatterns\Singleton\Tests;
Expand Down