generated from ergebnis/php-cs-fixer-config-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ergebnis/feature/header
Enhancement: Allow construction of header
- Loading branch information
Showing
17 changed files
with
1,029 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Header; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Author | ||
{ | ||
private $value; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return self | ||
*/ | ||
public static function fromString(string $value): self | ||
{ | ||
$trimmed = \trim($value); | ||
|
||
if ('' === $trimmed) { | ||
throw new \InvalidArgumentException('Value cannot be blank or empty.'); | ||
} | ||
|
||
return new self($trimmed); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Header; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CopyrightYears | ||
{ | ||
private $value; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @param Year $startYear | ||
* @param Year $endYear | ||
* | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return self | ||
*/ | ||
public static function fromRange(Year $startYear, Year $endYear): self | ||
{ | ||
if ($startYear->greaterThan($endYear)) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Start year "%s" needs to be equal to or less than end year "%s".', | ||
$startYear->toString(), | ||
$endYear->toString() | ||
)); | ||
} | ||
|
||
if ($startYear->equals($endYear)) { | ||
return self::fromYear($startYear); | ||
} | ||
|
||
return new self(\sprintf( | ||
'%s-%s', | ||
$startYear->toString(), | ||
$endYear->toString() | ||
)); | ||
} | ||
|
||
public static function fromYear(Year $year): self | ||
{ | ||
return new self($year->toString()); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Header; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Header | ||
{ | ||
private $copyrightYear; | ||
|
||
private $author; | ||
|
||
private $license; | ||
|
||
private $url; | ||
|
||
private function __construct(CopyrightYears $copyrightYear, Author $author, License $license, Url $url) | ||
{ | ||
$this->copyrightYear = $copyrightYear; | ||
$this->author = $author; | ||
$this->license = $license; | ||
$this->url = $url; | ||
} | ||
|
||
public static function create(CopyrightYears $copyrightYear, Author $author, License $license, Url $url): self | ||
{ | ||
return new self( | ||
$copyrightYear, | ||
$author, | ||
$license, | ||
$url | ||
); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
if ($this->license->isEmpty()) { | ||
return <<<EOF | ||
Copyright (c) {$this->copyrightYear->toString()} {$this->author->toString()} | ||
@see {$this->url->toString()} | ||
EOF; | ||
} | ||
|
||
return <<<EOF | ||
Copyright (c) {$this->copyrightYear->toString()} {$this->author->toString()} | ||
{$this->license->toString()} | ||
@see {$this->url->toString()} | ||
EOF; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Header; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class License | ||
{ | ||
private $value; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function fromString(string $value): self | ||
{ | ||
return new self(\trim($value)); | ||
} | ||
|
||
public function isEmpty(): bool | ||
{ | ||
return '' === $this->value; | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Header; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Url | ||
{ | ||
private $value; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return self | ||
*/ | ||
public static function fromString(string $value): self | ||
{ | ||
$trimmed = \trim($value); | ||
|
||
if (false === \filter_var($trimmed, \FILTER_VALIDATE_URL)) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value "%s" does not appear to be a valid URL.', | ||
$value | ||
)); | ||
} | ||
|
||
return new self($trimmed); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
Oops, something went wrong.