Skip to content

Commit

Permalink
Handlers for most types
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed May 22, 2018
1 parent 0d5000c commit c81f7ca
Show file tree
Hide file tree
Showing 31 changed files with 1,237 additions and 0 deletions.
99 changes: 99 additions & 0 deletions build.xml
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="Dogma" default="check-php">

<property name="file.mode.writable" value="0775"/>
<property name="path.bin" value="${path.root}/bin"/>
<property name="path.build" value="${path.root}/build"/>
<property name="path.composer.executable" value="composer"/>
<property name="path.php.executable" value="php"/>
<property name="path.phpcs.executable" value="${path.bin}/phpcs"/>
<property name="path.phpcs.ruleset" value="${path.build}/codesniffer/ruleset.xml"/>
<property name="path.phplint.executable" value="${path.bin}/parallel-lint"/>
<property name="path.phpstan.executable" value="${path.bin}/phpstan"/>
<property name="path.phpstan.config" value="${path.build}/phpstan/phpstan.neon"/>
<property name="path.root" value="${project.basedir}"/>
<property name="path.spell-checker.executable" value="${path.bin}/spell-checker"/>
<property name="path.spell-checker.config" value="${path.build}/spell-checker/spell-checker.neon"/>
<property name="path.src" value="${path.root}/src"/>
<property name="path.tester.executable" value="${path.bin}/tester"/>
<property name="path.tests" value="${path.root}/tests"/>

<!-- shortcuts -->
<target name="t" depends="tests"/>
<target name="tc" depends="tests-coverage"/>
<target name="da" depends="dump-autoload"/>

<target name="check" depends="check-php"/>

<target name="check-php" depends="phplint,phpcs,tests,phpstan,spell-check"/>

<target name="composer">
<exec executable="${path.composer.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="install"/>
</exec>
</target>

<target name="dump-autoload">
<exec executable="${path.composer.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="dump-autoload"/>
</exec>
</target>

<target name="phpcs">
<exec executable="${path.phpcs.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--standard=${path.phpcs.ruleset}"/>
<arg value="--extensions=php"/>
<arg value="--encoding=utf-8"/>
<arg value="--tab-width=4"/>
<arg value="-sp"/>
<arg path="${path.src}"/>
<arg path="${path.tests}"/>
</exec>
</target>

<target name="phplint">
<exec executable="${path.phplint.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg path="${path.src}"/>
<arg path="${path.tests}"/>
</exec>
</target>

<target name="phpstan">
<exec executable="${path.phpstan.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg line="analyse"/>
<arg line="-c ${path.phpstan.config}"/>
<arg line="-l 5"/>
<arg path="${path.src}"/>
<arg path="${path.tests}"/>
</exec>
</target>

<target name="tests">
<exec executable="${path.tester.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg path="${path.tests}"/>
<arg line="-c ${path.tests}"/>
<arg line="--colors 1"/>
</exec>
</target>

<target name="tests-coverage">
<exec executable="${path.tester.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg line="-p phpdbg"/>
<arg path="${path.tests}"/>
<arg line="-c ${path.tests}"/>
<arg line="--colors 1"/>
<arg line="--coverage ${path.tests}/coverage.html"/>
<arg line="--coverage-src ${path.src}"/>
</exec>
</target>

<target name="spell-check">
<exec executable="${path.spell-checker.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg line="--config ${path.spell-checker.config}"/>
<arg line="--checkDictionaryFiles"/>
<arg line="--memoryLimit 1024M"/>
<arg line="--noLogo"/>
</exec>
</target>

</project>
90 changes: 90 additions & 0 deletions build/codesniffer/ruleset.xml
@@ -0,0 +1,90 @@
<?xml version="1.0"?>
<ruleset name="Dogma">
<rule ref="../../vendor/consistence/coding-standard/Consistence/ruleset.xml">
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedIF"/><!-- allow empty if statements - usually with a comment -->
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedELSE"/><!-- allow empty else statements - usually with a comment -->
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedELSEIF"/><!-- allow empty elseif statements - usually with a comment -->
<exclude name="PEAR.WhiteSpace.ObjectOperatorIndent.Incorrect"/><!-- je potřeba odsazení u formů a dibi fluent -->
<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine"/><!-- string rozdělený na více řádků, typicky SQL -->
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments"/><!-- dibi syntaxe využívá argumentů "v textu" -->
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket"/><!-- conflicts with our way of writing multiline SQL queries -->
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/><!-- throws error with short type hint for integer and boolean -->
<exclude name="Squiz.PHP.InnerFunctions.NotAllowed"/><!-- prevents implementing anonymous classes -->
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces.NonFullyQualified"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessDocComment"/><!-- not taking @throws into account -->
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.WriteOnlyProperty"/><!-- not taking traits into account -->
</rule>
<rule ref="../../vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/><!-- false positive on array by reference -->
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/><!-- conflicts with PhpStan and PhpException -->
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod"/><!-- false positive on private method used by static constructor -->

<exclude name="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces.NoEmptyLineAfterOpeningBrace"/>
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName"/>
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants.NonFullyQualified"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword.NonFullyQualifiedImplements"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions.NonFullyQualifiedException"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword.NonFullyQualifiedExtends"/>
<exclude name="SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison"/>
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceBetweenOpenTagAndDeclare"/>
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceAfterDeclare"/>

<exclude-pattern>testClass</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="app/src=>AlterExecutor"/>
<property name="skipDirs" type="array" value="tests"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword">
<properties>
<property name="keywordsToCheck" type="array" value="T_EXTENDS,T_IMPLEMENTS"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="namespacesRequiredToUse" type="array" value="Dogma"/>
<property name="fullyQualifiedKeywords" type="array" value="T_EXTENDS,T_IMPLEMENTS"/>
<property name="allowFullyQualifiedExceptions" value="true"/>
<property name="allowPartialUses" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements">
<properties>
<property name="alwaysUsedPropertiesAnnotations" type="array" value="@get,@set"/>
<property name="alwaysUsedPropertiesSuffixes" type="array" value="Value,Timestamp"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Typehints.TypeHintDeclaration">
<properties>
<property name="traversableTypeHints" type="array" value="Traversable"/>
<property name="usefulAnnotations" type="array" value="@dataProvider,@deprecated,@internal,@label,@see"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.FunctionSpacing.After"/>
<rule ref="Squiz.Commenting.FunctionComment">
<exclude-pattern>tests/</exclude-pattern><!-- @dataProvider etc. annotations trigger comments check -->
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle"/><!-- bullshit -->
</rule>
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<exclude-pattern>/exceptions/</exclude-pattern>
<exclude-pattern>/tests/</exclude-pattern>
</rule>
<rule ref="Generic.Whitespace">
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/><!-- i like spaces -->
</rule>
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman">
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine"/><!-- ) { on separate line -->
</rule>
<rule ref="Generic.Commenting.Todo.TaskFound">
<exclude name="Generic.Commenting.Todo.TaskFound"/>
</rule>
</ruleset>
8 changes: 8 additions & 0 deletions build/phpstan/phpstan.neon
@@ -0,0 +1,8 @@

parameters:
ignoreErrors:
# strange
- '~^Parameter #1 $value of static method Dogma\Math\Decimal\Decimal::parse() expects string, string|int|null given.~'

# misleading
- '~^Parameter #1 $value of class Dogma\Math\Decimal\Decimal constructor expects string|int, int|string|Dogma\Math\Decimal\Decimal given.~' # if (!$x instanceof C)
7 changes: 7 additions & 0 deletions build/spell-checker/custom.dic
@@ -0,0 +1,7 @@

# code
inflector
instanceof
iso
tld
uri
21 changes: 21 additions & 0 deletions build/spell-checker/spell-checker.neon
@@ -0,0 +1,21 @@

directories:
- build
- src
- tests
- //

dictionariesByFileName: []

dictionariesByFileExtension:
neon: en custom
php: en php custom

dictionaryDirectories:
- build/spell-checker
- vendor/spell-checker

checkLocalIgnores: true

dictionaryFilesToCheck:
- custom.dic
36 changes: 36 additions & 0 deletions composer.json
@@ -0,0 +1,36 @@
{
"name": "dogma/dogma-doctrine",
"type": "library",
"description": "Doctrine type handlers for Dogma types.",
"homepage": "http://github.com/paranoiq/dogma-doctrine",
"license": ["BSD-3-Clause"],
"authors": [
{
"name": "Vlasta Neubauer",
"homepage": "http://www.paranoiq.cz"
}
],
"require": {
"php-64bit": "^7.1.0",
"doctrine/orm": "~2.6",
"tracy/tracy": "~2.4"
},
"require-dev": {
"consistence/coding-standard": "~2.3",
"jakub-onderka/php-console-highlighter": "~0.3",
"jakub-onderka/php-parallel-lint": "~0.8",
"nette/tester": "~1.7",
"phing/phing": "~2.16",
"phpstan/phpstan": "~0.8",
"slevomat/coding-standard": "~4.3",
"squizlabs/php_codesniffer": "~3.2",
"spell-checker/spell-checker": "~0.3",
"spell-checker/dictionary-en": "~0.1"
},
"autoload": {
"classmap": ["src"]
},
"config": {
"bin-dir": "bin"
}
}
30 changes: 30 additions & 0 deletions src/Country/CountryType.php
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);
/**
* This file is part of the Dogma library (https://github.com/paranoiq/dogma)
*
* Copyright (c) 2012 Vlasta Neubauer (@paranoiq)
*
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/

namespace Dogma\Doctrine\Country;

use Dogma\Country\Country;
use Dogma\Doctrine\Enum\StringEnumType;

class CountryType extends StringEnumType
{

public const NAME = 'country_type';

public function getName(): string
{
return self::NAME;
}

protected function getEnumClass(): string
{
return Country::class;
}

}
55 changes: 55 additions & 0 deletions src/Email/EmailAddressType.php
@@ -0,0 +1,55 @@
<?php declare(strict_types = 1);
/**
* This file is part of the Dogma library (https://github.com/paranoiq/dogma)
*
* Copyright (c) 2012 Vlasta Neubauer (@paranoiq)
*
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/

namespace Dogma\Doctrine\Email;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Dogma\Email\EmailAddress;
use PHPStan\Type\StringType;

class EmailAddressType extends StringType
{

public const NAME = 'email_address_type';

public function getName(): string
{
return self::NAME;
}

/**
* @param \Dogma\Email\EmailAddress|string|null $value
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
* @return \Dogma\Email\EmailAddress|null
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?EmailAddress
{
if ($value === null || $value instanceof EmailAddress) {
return $value;
}

return new EmailAddress($value);
}

/**
* @param \Dogma\Email\EmailAddress|string|null $value
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
* @return string|null
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
return $value instanceof EmailAddress ? $value->getValue() : $value;
}

public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}

}
30 changes: 30 additions & 0 deletions src/Email/EmailHeaderType.php
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);
/**
* This file is part of the Dogma library (https://github.com/paranoiq/dogma)
*
* Copyright (c) 2012 Vlasta Neubauer (@paranoiq)
*
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/

namespace Dogma\Doctrine\Email;

use Dogma\Doctrine\Enum\StringEnumType;
use Dogma\Email\EmailAddress;

class EmailHeaderType extends StringEnumType
{

public const NAME = 'email_address_type';

public function getName(): string
{
return self::NAME;
}

protected function getEnumClass(): string
{
return EmailAddress::class;
}

}

0 comments on commit c81f7ca

Please sign in to comment.