Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Code linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Frömer committed Jun 17, 2019
1 parent 1a82658 commit 423e4c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
19 changes: 10 additions & 9 deletions src/DeclareStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DeclareStatement
private const ALLOWED = [
self::TICKS => 'integer',
self::STRICT_TYPES => 'integer',
self::ENCODING => 'string'
self::ENCODING => 'string',
];

/**
Expand Down Expand Up @@ -50,37 +50,37 @@ public function getValue()

/**
* @param int $value
* @return DeclareStatement
* @return self
*/
public static function ticks(int $value): DeclareStatement
public static function ticks(int $value): self
{
return new self(self::TICKS, $value);
}

/**
* @param int $value
* @return DeclareStatement
* @return self
*/
public static function strictTypes(int $value): DeclareStatement
public static function strictTypes(int $value): self
{
return new self(self::STRICT_TYPES, $value);
}

/**
* @param string $value
* @return DeclareStatement
* @return self
*/
public static function encoding(string $value): DeclareStatement
public static function encoding(string $value): self
{
return new self(self::ENCODING, $value);
}

public static function fromArray(array $config): DeclareStatement
public static function fromArray(array $config): self
{
$directive = key($config);
$value = $config[$directive];

if (! array_key_exists($directive, self::ALLOWED)) {
if (! isset(self::ALLOWED[$directive])) {
throw new InvalidArgumentException(
sprintf(
'Declare directive must be on of: %s.',
Expand All @@ -100,6 +100,7 @@ public static function fromArray(array $config): DeclareStatement
}

$method = str_replace('_', '', lcfirst(ucwords($directive, '_')));

return self::{$method}($value);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Generator/FileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static function fromArray(array $values)
$fileGenerator->setRequiredFiles($value);
break;
case 'declares':
$fileGenerator->setDeclares(array_map(function ($directive, $value) {
$fileGenerator->setDeclares(array_map(static function ($directive, $value) {
return DeclareStatement::fromArray([$directive => $value]);
}, array_keys($value), $value));
break;
Expand Down Expand Up @@ -425,9 +425,9 @@ public function setDeclares(array $declares)
foreach ($declares as $declare) {
if (! $declare instanceof DeclareStatement) {
throw new InvalidArgumentException(sprintf(
'%s is expecting an array of %s\Declare objects',
'%s is expecting an array of %s objects',
__METHOD__,
__NAMESPACE__
DeclareStatement::class
));
}

Expand Down
18 changes: 9 additions & 9 deletions test/Generator/FileGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ public function testSingleDeclareStatement(): void
{
$generator = FileGenerator::fromArray([
'declares' => [
'strict_types' => 1
'strict_types' => 1,
],
'class' => [
'name' => 'SampleClass'
'name' => 'SampleClass',
],
]);
$generator->setFilename(sys_get_temp_dir() . '/result_file.php');
Expand Down Expand Up @@ -452,10 +452,10 @@ public function testMultiDeclareStatements(): void
$generator = FileGenerator::fromArray([
'declares' => [
'strict_types' => 1,
'ticks' => 2
'ticks' => 2,
],
'class' => [
'name' => 'SampleClass'
'name' => 'SampleClass',
],
]);
$generator->setFilename(sys_get_temp_dir() . '/result_file.php');
Expand Down Expand Up @@ -487,10 +487,10 @@ public function testDeclareUnknownDirectiveShouldRaiseException(): void

FileGenerator::fromArray([
'declares' => [
'fubar' => 1
'fubar' => 1,
],
'class' => [
'name' => 'SampleClass'
'name' => 'SampleClass',
],
]);
}
Expand All @@ -502,10 +502,10 @@ public function testDeclareWrongTypeShouldRaiseException(): void

FileGenerator::fromArray([
'declares' => [
'strict_types' => 'wrong type'
'strict_types' => 'wrong type',
],
'class' => [
'name' => 'SampleClass'
'name' => 'SampleClass',
],
]);
}
Expand All @@ -514,7 +514,7 @@ public function testDeclareDuplicatesShouldOnlyGenerateOne(): void
{
$generator = FileGenerator::fromArray([
'class' => [
'name' => 'SampleClass'
'name' => 'SampleClass',
],
]);
$generator->setFilename(sys_get_temp_dir() . '/result_file.php');
Expand Down

0 comments on commit 423e4c6

Please sign in to comment.