for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Compolomus\LSQLQueryBuilder\System;
class Fields
{
use Traits\Helper;
private $name;
private $allias = null;
private $result = null;
private $functionsList = [
'COMPRESS',
'MD5',
'PASSWORD',
'SHA',
'SHA1',
'UNCOMPRESS',
'UNCOMPRESSED_LENGTH',
'VALIDATE_PASSWORD_STRENGTH',
'AVG',
'BIT_AND',
'BIT_OR',
'BIT_XOR',
'BIT_COUNT',
'COUNT',
'GROUP_CONCAT',
'JSON_ARRAYAGG',
'MAX',
'MIN',
'STD',
'STDDEV',
'STDDEV_POP',
'STDDEV_SAMP',
'SUM',
'VAR_POP',
'VAR_SAMP',
'VARIANCE',
'ASCII',
'BIN',
'ORD',
'CHAR_LENGTH', // multibyte len
'HEX',
'OCT',
'LCASE',
'LOWER',
'UCASE',
'UPPER',
'REVERSE',
#'LOAD_FILE', // security
'TRIM', // rtrim
'LTRIM',
'RTRIM',
'ABS',
'ACOS',
'ASIN',
'ATAN',
'CEIL',
'CEILING',
'COS',
'COT',
'CRC32',
'DEGREES',
'EXP',
'FLOOR',
'LN',
'LOG',
'LOG2',
'LOG10',
'RADIANS',
'ROUND',
'SIGN',
'SIN',
'SQRT',
'TAN',
'DATE',
'DAY',
'DAYNAME',
'DAYOFMONTH',
'DAYOFWEEK',
'DAYOFYEAR',
'FROM_DAYS',
'FROM_UNIXTIME',
'HOUR',
'LAST_DAY',
'MICROSECOND',
'MINUTE',
'MONTH',
'MONTHNAME',
'QUARTER',
'SECOND',
'SEC_TO_TIME',
'TIME',
'TIME_TO_SEC',
'TO_DAYS',
'TO_SECONDS',
'UNIX_TIMESTAMP',
'WEEK',
'WEEKDAY',
'YEAR',
'YEARWEEK',
'WEEKOFYEAR',
];
public function __construct(string $name)
$this->result = $this->name = $this->escapeField($name);
}
public function allias(string $alliasName): void
$this->allias = $this->escapeField($alliasName);
public function function(string $functionName): void
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.
if (!in_array(strtoupper($functionName), $this->functionsList)) {
throw new \InvalidArgumentException('MYSQL Функция ' . $functionName . ' не найдена |SELECT setFunction|');
$this->result = strtoupper($functionName) . '(' . $this->name . ')';
$this
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
class A { var $property; }
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.
public function result(): string
return $this->result . (!is_null($this->allias) ? ' AS ' . $this->allias : '');