Adhere to PSR-12 coding styles
This commit is contained in:
parent
9653d7872e
commit
b5ddbab61f
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Useful PHP Traits
|
||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
|
@ -17,6 +18,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCC\Traits;
|
||||
|
||||
/**
|
||||
|
@ -24,25 +27,21 @@ namespace OCC\Traits;
|
|||
*
|
||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
* @package opencultureconsulting/traits
|
||||
* @access public
|
||||
*/
|
||||
trait Getter
|
||||
{
|
||||
/**
|
||||
* Read data from an inaccessible property.
|
||||
*
|
||||
* @access public
|
||||
* @final
|
||||
* @param string $property The class property to get
|
||||
*
|
||||
* @param string $property
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed The class property's current value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
final public function __get(string $property): mixed
|
||||
{
|
||||
$method = 'get' . ucfirst($property);
|
||||
$method = '_get' . ucfirst($property);
|
||||
if (
|
||||
property_exists(__CLASS__, $property)
|
||||
&& method_exists(__CLASS__, $method)
|
||||
|
@ -56,12 +55,9 @@ trait Getter
|
|||
/**
|
||||
* Check if an inaccessible property is set and not empty.
|
||||
*
|
||||
* @access public
|
||||
* @final
|
||||
* @param string $property The class property to check
|
||||
*
|
||||
* @param string $property
|
||||
*
|
||||
* @return bool
|
||||
* @return bool Whether the class property is set and not empty
|
||||
*/
|
||||
final public function __isset(string $property): bool
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Useful PHP Traits
|
||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
|
@ -17,6 +18,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCC\Traits;
|
||||
|
||||
/**
|
||||
|
@ -24,18 +27,14 @@ namespace OCC\Traits;
|
|||
*
|
||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
* @package opencultureconsulting/traits
|
||||
* @access public
|
||||
*/
|
||||
trait Setter
|
||||
{
|
||||
/**
|
||||
* Write data to an inaccessible property.
|
||||
*
|
||||
* @access public
|
||||
* @final
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
* @param string $property The class property to set
|
||||
* @param mixed $value The new value of the property
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
@ -43,7 +42,7 @@ trait Setter
|
|||
*/
|
||||
final public function __set(string $property, mixed $value): void
|
||||
{
|
||||
$method = 'set' . ucfirst($property);
|
||||
$method = '_set' . ucfirst($property);
|
||||
if (
|
||||
property_exists(__CLASS__, $property)
|
||||
&& method_exists(__CLASS__, $method)
|
||||
|
@ -57,10 +56,7 @@ trait Setter
|
|||
/**
|
||||
* Unset an inaccessible property.
|
||||
*
|
||||
* @access public
|
||||
* @final
|
||||
*
|
||||
* @param string $property
|
||||
* @param string $property The class property to unset
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Useful PHP Traits
|
||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
|
@ -17,35 +18,25 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCC\Traits;
|
||||
|
||||
/**
|
||||
* Allows just a single instance of a class.
|
||||
* Allows just a single instance of the class using this trait.
|
||||
*
|
||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
* @package opencultureconsulting/traits
|
||||
* @access public
|
||||
*/
|
||||
trait Singleton
|
||||
{
|
||||
/**
|
||||
* Holds the singleton instance.
|
||||
*
|
||||
* @access private
|
||||
* @static
|
||||
*
|
||||
* @var self
|
||||
* Holds the singleton instances.
|
||||
*/
|
||||
private static ?self $singleton;
|
||||
|
||||
/**
|
||||
* Get a singleton instance of this class.
|
||||
*
|
||||
* @access public
|
||||
* @final
|
||||
* @static
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
final public static function getInstance(): self
|
||||
{
|
||||
|
@ -59,18 +50,11 @@ trait Singleton
|
|||
/**
|
||||
* This is a singleton class, thus the constructor is private.
|
||||
* (Get an instance of this class by calling self::getInstance())
|
||||
*
|
||||
* @access private
|
||||
* @abstract
|
||||
*/
|
||||
abstract private function __construct();
|
||||
|
||||
/**
|
||||
* This is a singleton class, thus cloning is prohibited.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final private function __clone(): void
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue