Skip to content

Commit

Permalink
Code style update and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hgraca committed Mar 4, 2020
1 parent 757f55d commit b849575
Show file tree
Hide file tree
Showing 100 changed files with 613 additions and 476 deletions.
14 changes: 14 additions & 0 deletions .php_cs.dist
Expand Up @@ -24,33 +24,47 @@ return PhpCsFixer\Config::create()
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'class_definition' => [
'multiLineExtendsEachSingleLine' => true,
],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'final_internal_class' => false, // false because otherwise internal classes can not have subclasses
'fully_qualified_strict_types' => true,
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
'heredoc_indentation' => true,
'linebreak_after_opening_tag' => true,
'mb_str_functions' => true,
'native_function_invocation' => [],
'no_multiline_whitespace_before_semicolons' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_superfluous_phpdoc_tags' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['class', 'function', 'const'],
],
'php_unit_internal_class' => true,
'php_unit_method_casing' => ['case' => 'snake_case'],
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_size_class' => ['group' => 'small'],
'php_unit_strict' => false, // false because otherwise self::assertEquals => self::assertSame
'php_unit_test_annotation' => [
'style' => 'annotation',
],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_align' => false,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'pre_increment' => false,
'return_type_declaration' => ['space_before' => 'none'],
'semicolon_after_instruction' => true,
'single_line_throw' => false,
'strict_comparison' => true,
'strict_param' => true,
'void_return' => true,
Expand Down
3 changes: 0 additions & 3 deletions lib/php-extension/src/Enum/AbstractEnum.php
Expand Up @@ -77,9 +77,6 @@ public function __call(string $methodName, array $arguments)
throw new BadMethodCallException(sprintf('%s::%s() does not exist', static::class, $methodName));
}

/**
* @return mixed
*/
public function getValue()
{
return $this->value;
Expand Down
4 changes: 0 additions & 4 deletions lib/php-extension/src/Helper/ReflectionHelper.php
Expand Up @@ -48,8 +48,6 @@ public static function setProtectedProperty($object, string $propertyName, $valu

/**
* @throws ReflectionException
*
* @return mixed
*/
public static function instantiateWithoutConstructor(string $classFqcn)
{
Expand All @@ -60,8 +58,6 @@ public static function instantiateWithoutConstructor(string $classFqcn)

/**
* @throws ReflectionException
*
* @return mixed
*/
public static function invokeProtectedMethod($object, string $methodName, array $arguments = [])
{
Expand Down
Expand Up @@ -16,6 +16,8 @@

/**
* @small
*
* @internal
*/
final class ConstructableFromArrayTraitUnitTest extends AbstractUnitTest
{
Expand All @@ -24,7 +26,7 @@ final class ConstructableFromArrayTraitUnitTest extends AbstractUnitTest
*
* @throws \ReflectionException
*/
public function fromArray(): void
public function from_array(): void
{
$value = 123;

Expand All @@ -37,12 +39,13 @@ public function fromArray(): void

/**
* @test
* @expectedException \Exception
*
* @throws \ReflectionException
*/
public function fromArray_ThrowsExceptionIfArgumentIsMissing(): void
public function from_array_Throws_exception_if_argument_is_missing(): void
{
$this->expectException(\Exception::class);

$value = 123;

$dto = DummyConstructableFromArray::fromArray(['inexistent' => 'foo']);
Expand Down
Expand Up @@ -21,6 +21,8 @@

/**
* @small
*
* @internal
*/
final class DateTimeGeneratorUnitTest extends AbstractUnitTest
{
Expand Down Expand Up @@ -62,7 +64,7 @@ public function provideDateTime(): array
*
* @throws \Exception
*/
public function overrideDefaultGenerator(): void
public function override_default_generator(): void
{
$date = '2018-10-21';
DateTimeGenerator::overrideDefaultGenerator(
Expand Down
3 changes: 0 additions & 3 deletions lib/php-extension/tests/DummyConstructableFromArray.php
Expand Up @@ -37,9 +37,6 @@ public function __construct($prop1, $prop2 = 0)
$this->prop2 = $prop2;
}

/**
* @return mixed
*/
public function getProp1()
{
return $this->prop1;
Expand Down
27 changes: 14 additions & 13 deletions lib/php-extension/tests/Enum/AbstractEnumUnitTest.php
Expand Up @@ -18,6 +18,8 @@

/**
* @small
*
* @internal
*/
final class AbstractEnumUnitTest extends AbstractUnitTest
{
Expand Down Expand Up @@ -117,25 +119,24 @@ public function equals_should_return_true_when_comparing_objects_with_different_

/**
* @test
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Value [anything] is not matching any valid value of class "TestEnum". Valid values are ['A', 'BEE', 1, 3, NULL, true].
*/
public function exception_message(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Value [anything] is not matching any valid value of class "TestEnum". Valid values are [\'A\', \'BEE\', 1, 3, NULL, true].');

TestEnum::get('anything');
}

/**
* @test
*
* @dataProvider getInvertedCaseOptions
* @expectedException \InvalidArgumentException
*
* @param mixed $option
*/
public function get_with_inverted_case_is_incorrect($option): void
{
$this->expectException(\InvalidArgumentException::class);

TestEnum::get($option);
}

Expand All @@ -149,11 +150,11 @@ public function getInvertedCaseOptions(): array

/**
* @test
*
* @expectedException \InvalidArgumentException
*/
public function get_with_strict_equal_match_throws_exception(): void
{
$this->expectException(\InvalidArgumentException::class);

TestEnum::get('1');
}

Expand All @@ -170,19 +171,19 @@ public function is_should_allow_to_call_methods_based_on_constant_names(): void

/**
* @test
*
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Acme\PhpExtension\Test\Enum\TestEnum::isDoesNotExist() does not exist
*/
public function is_should_throw_an_exception_when_when_calling_an_invalid_method(): void
{
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Acme\\PhpExtension\\Test\\Enum\\TestEnum::isDoesNotExist() does not exist');

TestEnum::isDoesNotExist();
}

/**
* @test
*/
public function getValidOptions(): void
public function get_valid_options(): void
{
self::assertSame(
[
Expand All @@ -200,7 +201,7 @@ public function getValidOptions(): void
/**
* @test
*/
public function getKey(): void
public function get_key(): void
{
$enum = TestEnum::b();

Expand Down
Expand Up @@ -21,6 +21,8 @@

/**
* @small
*
* @internal
*/
final class AcmeExceptionTraitUnitTest extends AbstractUnitTest
{
Expand Down
Expand Up @@ -19,6 +19,8 @@

/**
* @small
*
* @internal
*/
final class AcmeLogicExceptionUnitTest extends AbstractUnitTest
{
Expand Down
Expand Up @@ -19,6 +19,8 @@

/**
* @small
*
* @internal
*/
final class AcmeRuntimeExceptionUnitTest extends AbstractUnitTest
{
Expand Down
8 changes: 5 additions & 3 deletions lib/php-extension/tests/Helper/ClassHelperUnitTest.php
Expand Up @@ -19,24 +19,26 @@

/**
* @small
*
* @internal
*/
final class ClassHelperUnitTest extends AbstractUnitTest
{
/**
* @test
*/
public function extractCanonicalClassName(): void
public function extract_canonical_class_name(): void
{
self::assertSame('ClassHelperUnitTest', ClassHelper::extractCanonicalClassName(__CLASS__));
}

/**
* @test
*/
public function extractCanonicalMethodName(): void
public function extract_canonical_method_name(): void
{
self::assertSame(
'extractCanonicalMethodName',
'extract_canonical_method_name',
ClassHelper::extractCanonicalMethodName(__METHOD__)
);
}
Expand Down
35 changes: 19 additions & 16 deletions lib/php-extension/tests/Helper/ReflectionHelperUnitTest.php
Expand Up @@ -19,6 +19,8 @@

/**
* @small
*
* @internal
*/
final class ReflectionHelperUnitTest extends AbstractUnitTest
{
Expand All @@ -27,7 +29,7 @@ final class ReflectionHelperUnitTest extends AbstractUnitTest
*
* @throws \ReflectionException
*/
public function getProtectedProperty_from_object_class(): void
public function get_protected_property_from_object_class(): void
{
$value = 7;
$object = new DummyClass($value);
Expand All @@ -40,7 +42,7 @@ public function getProtectedProperty_from_object_class(): void
*
* @throws \ReflectionException
*/
public function getProtectedProperty_from_object_parent_class(): void
public function get_protected_property_from_object_parent_class(): void
{
$value = 7;
$parentValue = 19;
Expand All @@ -52,12 +54,12 @@ public function getProtectedProperty_from_object_parent_class(): void
/**
* @test
*
* @expectedException \ReflectionException
*
* @throws \ReflectionException
*/
public function getProtectedProperty_throws_exception_if_not_found(): void
public function get_protected_property_throws_exception_if_not_found(): void
{
$this->expectException(\ReflectionException::class);

$object = new DummyClass();

ReflectionHelper::getProtectedProperty($object, 'inexistentVar');
Expand All @@ -68,38 +70,39 @@ public function getProtectedProperty_throws_exception_if_not_found(): void
*
* @throws \ReflectionException
*/
public function setProtectedProperty(): void
public function set_protected_property(): void
{
$newValue = 'something new';
$object = new DummyClass();
$this->assertNotSame($newValue, $object->getTestProperty());
self::assertNotSame($newValue, $object->getTestProperty());

ReflectionHelper::setProtectedProperty($object, 'testProperty', $newValue);
$this->assertSame($newValue, $object->getTestProperty());
self::assertSame($newValue, $object->getTestProperty());
}

/**
* @test
*
* @throws \ReflectionException
*/
public function setProtectedProperty_defined_in_parent_class(): void
public function set_protected_property_defined_in_parent_class(): void
{
$newValue = 'something new';
$object = new DummyClass();
$this->assertNotSame($newValue, $object->getParentTestProperty());
self::assertNotSame($newValue, $object->getParentTestProperty());

ReflectionHelper::setProtectedProperty($object, 'parentTestProperty', $newValue);
$this->assertSame($newValue, $object->getParentTestProperty());
self::assertSame($newValue, $object->getParentTestProperty());
}

/**
* @test
* @expectedException \ReflectionException
* @expectedExceptionMessage Property i_dont_exist does not exist
*/
public function setProtectedProperty_fails_when_cant_find_the_property(): void
public function set_protected_property_fails_when_cant_find_the_property(): void
{
$this->expectException(\ReflectionException::class);
$this->expectExceptionMessage('Property i_dont_exist does not exist');

$object = new DummyClass();
ReflectionHelper::setProtectedProperty($object, 'i_dont_exist', 'non existent');
}
Expand All @@ -109,10 +112,10 @@ public function setProtectedProperty_fails_when_cant_find_the_property(): void
*
* @throws \ReflectionException
*/
public function instantiateWithoutConstructor_does_not_use_the_constructor(): void
public function instantiate_without_constructor_does_not_use_the_constructor(): void
{
$object = ReflectionHelper::instantiateWithoutConstructor(DummyClass::class);
$this->assertNull($object->getAnotherVar());
self::assertNull($object->getAnotherVar());
}

/**
Expand Down

0 comments on commit b849575

Please sign in to comment.