Skip to content

Commit

Permalink
🎨 PSR-12 styling
Browse files Browse the repository at this point in the history
  • Loading branch information
synio-wesley committed Mar 17, 2024
1 parent 8e40e0b commit 36edc56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 172 deletions.
153 changes: 10 additions & 143 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,157 +1,24 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for PHP_CodeSniffer itself.</description>
<description>PSR-12 based coding style</description>

<file>src</file>

<exclude-pattern>*/src/Standards/*/Tests/*\.(inc|css|js)$</exclude-pattern>
<exclude-pattern>*/tests/Core/*/*\.(inc|css|js)$</exclude-pattern>
<exclude-pattern>*/tests/Core/*/Fixtures/*\.php$</exclude-pattern>
<file>tests</file>

<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>
<arg value="sp"/> <!-- Show sniff and progress -->

<!-- Don't hide tokenizer exceptions -->
<rule ref="Internal.Tokenizer.Exception">
<type>error</type>
</rule>

<!-- Include the whole PEAR standard -->
<rule ref="PEAR">
<exclude name="PEAR.NamingConventions.ValidFunctionName"/>
<exclude name="PEAR.NamingConventions.ValidVariableName"/>
<exclude name="PEAR.Commenting.ClassComment"/>
<exclude name="PEAR.Commenting.FileComment.MissingCategoryTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingPackageTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingLinkTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingVersion"/>
<exclude name="PEAR.Commenting.FileComment.Missing"/>
<exclude name="PEAR.Commenting.InlineComment"/>
</rule>

<!-- Include some sniffs from other standards that don't conflict with PEAR -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration"/>
<rule ref="Squiz.ControlStructures.ControlSignature"/>
<rule ref="Squiz.ControlStructures.ElseIfDeclaration"/>
<rule ref="Squiz.Commenting.BlockComment"/>
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<rule ref="Squiz.Commenting.EmptyCatchComment"/>
<rule ref="Squiz.Commenting.InlineComment"/>
<rule ref="Squiz.Commenting.PostStatementComment"/>
<rule ref="Squiz.Commenting.VariableComment"/>
<rule ref="Squiz.Formatting.OperatorBracket"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"/>
<rule ref="Squiz.Operators.ComparisonOperatorUsage"/>
<rule ref="Squiz.PHP.DisallowInlineIf"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Strings.ConcatenationSpacing"/>
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing"/>
<rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace"/>
<rule ref="Squiz.WhiteSpace.FunctionSpacing"/>
<rule ref="Squiz.WhiteSpace.MemberVarSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.ControlStructures.DisallowYodaConditions"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
<rule ref="PSR2.Classes.PropertyDeclaration"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Files.EndFileNewline"/>
<rule ref="PSR12.Files.OpenTag"/>
<rule ref="Zend.Files.ClosingTag"/>

<!-- PEAR uses warnings for inline control structures, so switch back to errors -->
<rule ref="Generic.ControlStructures.InlineControlStructure">
<properties>
<property name="error" value="true"/>
</properties>
</rule>

<!-- We use custom indent rules for arrays -->
<rule ref="Generic.Arrays.ArrayIndent"/>
<rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNewLine">
<severity>0</severity>
</rule>

<!-- Check var names, but we don't want leading underscores for private vars -->
<rule ref="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
<severity>0</severity>
</rule>
<!-- Show sniff and progress -->
<arg value="sp"/>

<!-- Only one argument per line in multi-line function calls -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>
<!-- PSR12 based -->
<rule ref="PSR12"/>

<!-- Have 12 chars padding maximum and always show as errors -->
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<!-- Lines can be N chars long (warnings), errors at M chars -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="maxPadding" value="12"/>
<property name="error" value="true"/>
<property name="lineLimit" value="130"/>
<property name="absoluteLineLimit" value="180"/>
</properties>
</rule>

<!-- Ban some functions -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="is_null" value="null"/>
<element key="create_function" value="null"/>
</property>
</properties>
</rule>

<!-- Private methods MUST not be prefixed with an underscore -->
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<type>error</type>
</rule>

<!-- Private properties MUST not be prefixed with an underscore -->
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<type>error</type>
</rule>

<!-- The testing bootstrap file uses string concats to stop IDEs seeing the class aliases -->
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>
</rule>

<!-- This test file specifically *needs* Windows line endings for testing purposes. -->
<rule ref="Generic.Files.LineEndings.InvalidEOLChar">
<exclude-pattern>tests/Core/Tokenizer/StableCommentWhitespaceWinTest\.php</exclude-pattern>
</rule>

<!-- Lines can be N chars long (warnings), errors at M chars -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="130"/>
<property name="absoluteLineLimit" value="180"/>
</properties>
</rule>

</ruleset>
37 changes: 14 additions & 23 deletions src/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class Catalog
{

/**
* The connection to the MariaDB server.
*
Expand Down Expand Up @@ -43,12 +42,12 @@ class Catalog
* @throws Exception If a general error occurs during instantiation.
*/
public function __construct(
protected string $dbHost='localhost',
protected int $dbPort=3306,
protected string $dbUser='root',
protected string $dbPass='',
protected ?array $dbOptions=null,
protected ?\PDO $pdo=null
protected string $dbHost = 'localhost',
protected int $dbPort = 3306,
protected string $dbUser = 'root',
protected string $dbPass = '',
protected ?array $dbOptions = null,
protected ?\PDO $pdo = null
) {
// Connect.
try {
Expand All @@ -73,10 +72,9 @@ public function __construct(

if (version_compare($version, self::MINIMAL_MARIA_VERSION, '<') === true) {
throw new Exception(
'The MariaDB version is too low. The minimal version is '.self::MINIMAL_MARIA_VERSION
'The MariaDB version is too low. The minimal version is ' . self::MINIMAL_MARIA_VERSION
);
}

}


Expand All @@ -103,8 +101,8 @@ public function create(string $catName): int
'src/create_catalog_sql/maria_add_gis_sp.sql',
'src/create_catalog_sql/mysql_sys_schema.sql',
];
$this->connection->exec('CREATE CATALOG IF NOT EXISTS '.$catName);
$this->connection->exec('USE CATALOG '.$catName);
$this->connection->exec('CREATE CATALOG IF NOT EXISTS ' . $catName);
$this->connection->exec('USE CATALOG ' . $catName);

$this->connection->exec('CREATE DATABASE IF NOT EXISTS mysql');
$this->connection->exec('USE mysql');
Expand Down Expand Up @@ -137,7 +135,6 @@ public function create(string $catName): int
}

return $this->getPort($catName);

}


Expand All @@ -152,7 +149,6 @@ public function getPort(string $catName): int
{
// TODO: wait for the functionality to be implemented in the server.
return ($this->dbPort ?? 0);

}


Expand All @@ -165,13 +161,13 @@ public function list(): array
{
$catalogs = [];
$results = $this->connection->query('SHOW CATALOGS');

foreach ($results as $row) {
// For now, we just return the default port for all catalogs.
$catalogs[$row['Catalog']] = $this->dbPort;
}

return $catalogs;

}


Expand All @@ -189,7 +185,7 @@ public function drop(string $catName): bool
{
try {
// Enter the catalog.
$this->connection->exec('USE CATALOG '.$catName);
$this->connection->exec('USE CATALOG ' . $catName);

// Check if there are any tables besides mysql, sys, performance_schema and information_schema.
$tables = $this->connection->query('SHOW DATABASES');
Expand All @@ -205,13 +201,12 @@ public function drop(string $catName): bool
$this->connection->exec('DROP DATABASE IF EXISTS performance_schema');

// Drop the catalog.
$this->connection->exec('DROP CATALOG '.$catName);
$this->connection->exec('DROP CATALOG ' . $catName);
} catch (\PDOException $e) {
throw new \Exception('Error dropping catalog: '.$e->getMessage());
throw new \Exception('Error dropping catalog: ' . $e->getMessage());
}

return true;

}


Expand All @@ -225,7 +220,6 @@ private function alter()
{
// PHPCS:ignore
// TODO implement the ALTER CATALOG command.

}


Expand All @@ -243,7 +237,7 @@ public function createAdminUserForCatalog(
string $catalog,
string $userName,
string $password,
string $authHost='localhost'
string $authHost = 'localhost'
): void {
$this->connection->exec("USE CATALOG {$catalog}");
$this->connection->exec("USE mysql");
Expand All @@ -262,8 +256,5 @@ public function createAdminUserForCatalog(
$this->connection->prepare(
"GRANT ALL PRIVILEGES ON `%`.* TO ?@? IDENTIFIED BY ? WITH GRANT OPTION;"
)->execute([$userName, $authHost, $password]);

}


}
7 changes: 1 addition & 6 deletions src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
class Exception extends \Exception
{


/**
* Constructs the Exception.
*
Expand All @@ -29,11 +27,8 @@ class Exception extends \Exception
* @param int $code The Exception code (optional).
* @param \Throwable|null $previous The previous throwable used for exception chaining (optional).
*/
public function __construct($message, $code=0, \Throwable $previous=null)
public function __construct($message, $code = 0, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);

}


}

0 comments on commit 36edc56

Please sign in to comment.