Adhere to PSR-12 coding styles

This commit is contained in:
Sebastian Meyer 2023-10-11 13:31:20 +02:00
parent 9653d7872e
commit b5ddbab61f
3 changed files with 23 additions and 47 deletions

View File

@ -1,4 +1,5 @@
<?php declare(strict_types=1); <?php
/** /**
* Useful PHP Traits * Useful PHP Traits
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
declare(strict_types=1);
namespace OCC\Traits; namespace OCC\Traits;
/** /**
@ -24,25 +27,21 @@ namespace OCC\Traits;
* *
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package opencultureconsulting/traits * @package opencultureconsulting/traits
* @access public
*/ */
trait Getter trait Getter
{ {
/** /**
* Read data from an inaccessible property. * Read data from an inaccessible property.
* *
* @access public * @param string $property The class property to get
* @final
* *
* @param string $property * @return mixed The class property's current value
*
* @return mixed
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
final public function __get(string $property): mixed final public function __get(string $property): mixed
{ {
$method = 'get' . ucfirst($property); $method = '_get' . ucfirst($property);
if ( if (
property_exists(__CLASS__, $property) property_exists(__CLASS__, $property)
&& method_exists(__CLASS__, $method) && method_exists(__CLASS__, $method)
@ -56,12 +55,9 @@ trait Getter
/** /**
* Check if an inaccessible property is set and not empty. * Check if an inaccessible property is set and not empty.
* *
* @access public * @param string $property The class property to check
* @final
* *
* @param string $property * @return bool Whether the class property is set and not empty
*
* @return bool
*/ */
final public function __isset(string $property): bool final public function __isset(string $property): bool
{ {

View File

@ -1,4 +1,5 @@
<?php declare(strict_types=1); <?php
/** /**
* Useful PHP Traits * Useful PHP Traits
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
declare(strict_types=1);
namespace OCC\Traits; namespace OCC\Traits;
/** /**
@ -24,18 +27,14 @@ namespace OCC\Traits;
* *
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package opencultureconsulting/traits * @package opencultureconsulting/traits
* @access public
*/ */
trait Setter trait Setter
{ {
/** /**
* Write data to an inaccessible property. * Write data to an inaccessible property.
* *
* @access public * @param string $property The class property to set
* @final * @param mixed $value The new value of the property
*
* @param string $property
* @param mixed $value
* *
* @return void * @return void
* *
@ -43,7 +42,7 @@ trait Setter
*/ */
final public function __set(string $property, mixed $value): void final public function __set(string $property, mixed $value): void
{ {
$method = 'set' . ucfirst($property); $method = '_set' . ucfirst($property);
if ( if (
property_exists(__CLASS__, $property) property_exists(__CLASS__, $property)
&& method_exists(__CLASS__, $method) && method_exists(__CLASS__, $method)
@ -57,10 +56,7 @@ trait Setter
/** /**
* Unset an inaccessible property. * Unset an inaccessible property.
* *
* @access public * @param string $property The class property to unset
* @final
*
* @param string $property
* *
* @return void * @return void
* *

View File

@ -1,4 +1,5 @@
<?php declare(strict_types=1); <?php
/** /**
* Useful PHP Traits * Useful PHP Traits
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
declare(strict_types=1);
namespace OCC\Traits; 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> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package opencultureconsulting/traits * @package opencultureconsulting/traits
* @access public
*/ */
trait Singleton trait Singleton
{ {
/** /**
* Holds the singleton instance. * Holds the singleton instances.
*
* @access private
* @static
*
* @var self
*/ */
private static ?self $singleton; private static ?self $singleton;
/** /**
* Get a singleton instance of this class. * Get a singleton instance of this class.
*
* @access public
* @final
* @static
*
* @return self
*/ */
final public static function getInstance(): self final public static function getInstance(): self
{ {
@ -59,18 +50,11 @@ trait Singleton
/** /**
* This is a singleton class, thus the constructor is private. * This is a singleton class, thus the constructor is private.
* (Get an instance of this class by calling self::getInstance()) * (Get an instance of this class by calling self::getInstance())
*
* @access private
* @abstract
*/ */
abstract private function __construct(); abstract private function __construct();
/** /**
* This is a singleton class, thus cloning is prohibited. * This is a singleton class, thus cloning is prohibited.
*
* @access private
*
* @return void
*/ */
final private function __clone(): void final private function __clone(): void
{ {