Skip to content

Commit ede3ae7

Browse files
authored
Merge pull request #66 from samsonasik/apply-zend-coding-standard
Apply zend coding standard
2 parents 3069848 + 7cafd19 commit ede3ae7

20 files changed

+76
-33
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
/phpstan.neon export-ignore
77
/spec/ export-ignore
88
/CONTRIBUTING.md export-ignore
9-
/kahlan-config.php export-ignore
9+
/kahlan-config.php export-ignore
10+
/phpcs.xml export-ignore

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ before_script:
1717
- composer dump-autoload -o
1818

1919
script:
20+
- composer cs-check
2021
- if [[ $TRAVIS_PHP_VERSION = 7.1 ]]; then bin/phpstan analyse src/ --level=max -c phpstan.neon; fi
2122
- if [[ $TRAVIS_PHP_VERSION != "nightly" ]]; then bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml; fi
2223
- if [[ $TRAVIS_PHP_VERSION = "nightly" ]]; then bin/kahlan; fi

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CONTRIBUTING
33
To contribute, you can send pull requests with :
44

55
- Typo fix.
6-
- Use PSR-2 Coding Standard.
6+
- Use [Zend Coding Standard](https://github.com/zendframework/zend-coding-standard).
77
- patch(es) need new/updated test(s).
88
- new feature(s) need test(s).
99

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"phpstan/phpstan-webmozart-assert": "^0.10.0",
6868
"pimple/pimple": "^3.2",
6969
"symfony/dependency-injection": "^4.0",
70+
"zendframework/zend-coding-standard": "^1.0",
7071
"zendframework/zend-expressive": "^3.0",
7172
"zendframework/zend-expressive-zendviewrenderer": "^2.0",
7273
"zendframework/zend-mvc": "^3.0",
@@ -100,5 +101,9 @@
100101
"psr-4": {
101102
"ErrorHeroModule\\Spec\\": "spec/"
102103
}
104+
},
105+
"scripts": {
106+
"cs-check": "phpcs",
107+
"cs-fix": "phpcbf"
103108
}
104109
}

phpcs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Zend Framework Coding Standard">
3+
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
4+
5+
<!-- Paths to check -->
6+
<file>src</file>
7+
</ruleset>

src/Controller/ErrorPreviewController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function noticeAction()
2626

2727
public function fatalAction()
2828
{
29-
$y = new class implements \stdClass {};
29+
$y = new class implements \stdClass {
30+
};
3031
}
3132
}

src/Handler/Logging.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,22 @@ public function __construct(
7575
/**
7676
* @throws RuntimeException when cannot connect to DB in the first place
7777
*/
78-
private function isExists(string $errorFile, int $errorLine, string $errorMessage, string $url, string $errorType) : bool
79-
{
78+
private function isExists(
79+
string $errorFile,
80+
int $errorLine,
81+
string $errorMessage,
82+
string $url,
83+
string $errorType
84+
) : bool {
8085
$writers = $this->logger->getWriters()->toArray();
8186
foreach ($writers as $writer) {
8287
if ($writer instanceof Db) {
8388
try {
84-
$handlerWriterDb = new Writer\Checker\Db($writer, $this->configLoggingSettings, $this->logWritersConfig);
89+
$handlerWriterDb = new Writer\Checker\Db(
90+
$writer,
91+
$this->configLoggingSettings,
92+
$this->logWritersConfig
93+
);
8594
if ($handlerWriterDb->isExists($errorFile, $errorLine, $errorMessage, $url, $errorType)) {
8695
return true;
8796
}
@@ -212,14 +221,13 @@ public function handleErrorException(Throwable $t, RequestInterface $request) :
212221
$serverUrl = $extra['server_url'];
213222

214223
try {
215-
if (
216-
$this->isExists(
217-
$collectedExceptionData['errorFile'],
218-
$collectedExceptionData['errorLine'],
219-
$collectedExceptionData['errorMessage'],
220-
$extra['url'],
221-
$collectedExceptionData['errorType']
222-
)
224+
if ($this->isExists(
225+
$collectedExceptionData['errorFile'],
226+
$collectedExceptionData['errorLine'],
227+
$collectedExceptionData['errorMessage'],
228+
$extra['url'],
229+
$collectedExceptionData['errorType']
230+
)
223231
) {
224232
return;
225233
}
@@ -232,6 +240,11 @@ public function handleErrorException(Throwable $t, RequestInterface $request) :
232240
unset($extra['server_url']);
233241
}
234242

235-
$this->sendMail($collectedExceptionData['priority'], $collectedExceptionData['errorMessage'], $extra, '['.$serverUrl.'] '.$collectedExceptionData['errorType'].' has thrown');
243+
$this->sendMail(
244+
$collectedExceptionData['priority'],
245+
$collectedExceptionData['errorMessage'],
246+
$extra,
247+
'[' . $serverUrl . '] ' . $collectedExceptionData['errorType'] . ' has thrown'
248+
);
236249
}
237250
}

src/Handler/LoggingFactory.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
class LoggingFactory
1313
{
1414
/**
15-
* @throws RuntimeException when mail config is enabled but mail-message config is not a service instance of Message
16-
* @throws RuntimeException when mail config is enabled but mail-transport config is not a service instance of TransportInterface
15+
* @throws RuntimeException when mail config is enabled
16+
* but mail-message and/or mail-transport config is not a service instance of Message
1717
*/
1818
public function __invoke(ContainerInterface $container) : Logging
1919
{
@@ -30,12 +30,18 @@ public function __invoke(ContainerInterface $container) : Logging
3030
if ($mailConfig['enable'] === true) {
3131
$mailMessageService = $container->get($mailConfig['mail-message']);
3232
if (! $mailMessageService instanceof Message) {
33-
throw new RuntimeException('You are enabling email log writer, your "mail-message" config must be instanceof '.Message::class);
33+
throw new RuntimeException(sprintf(
34+
'You are enabling email log writer, your "mail-message" config must be instanceof %s',
35+
Message::class
36+
));
3437
}
3538

3639
$mailMessageTransport = $container->get($mailConfig['mail-transport']);
3740
if (! $mailMessageTransport instanceof TransportInterface) {
38-
throw new RuntimeException('You are enabling email log writer, your "mail-transport" config must implements '.TransportInterface::class);
41+
throw new RuntimeException(sprintf(
42+
'You are enabling email log writer, your "mail-transport" config must implements %s',
43+
TransportInterface::class
44+
));
3945
}
4046
}
4147

src/Handler/Writer/Checker/Db.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ public function __construct(
3636
$this->logWritersConfig = $logWritersConfig;
3737
}
3838

39-
public function isExists(string $errorFile, int $errorLine, string $errorMessage, string $errorUrl, string $errorType) : bool
40-
{
39+
public function isExists(
40+
string $errorFile,
41+
int $errorLine,
42+
string $errorMessage,
43+
string $errorUrl,
44+
string $errorType
45+
) : bool {
4146
// db definition
4247
$db = Closure::bind(function ($dbWriter) {
4348
return $dbWriter->db;

src/HeroFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ function detectMessageContentType(string $message) : string
1111
return (new JsonParser())->lint($message) === null
1212
? 'application/problem+json'
1313
: ((\strip_tags($message) === $message) ? 'text/plain' : 'text/html');
14-
}
14+
}

0 commit comments

Comments
 (0)