Created
January 19, 2023 10:27
-
-
Save webdevilopers/2c37b7343974774affb2cba2ba1caf56 to your computer and use it in GitHub Desktop.
Early Return Developer vs. OpenAI ChatGTP vs. PHPStorm PHP Inspections
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
<?php declare(strict_types=1); | |
final class DocumentFormatValidator | |
{ | |
private function validatePrefix(Filename $filename, DocumentFormat $format): void | |
{ | |
$detectedPrefix = $this->detectPrefix($filename); | |
if ($detectedPrefix === null) { | |
if (!$format->requiresPrefix()) { | |
return; | |
} | |
throw new DomainException('Missing prefix.'); | |
} | |
if (!$format->requiresPrefix()) { | |
throw new DomainException('Non required prefix detected.'); | |
} | |
if (in_array($detectedPrefix->toString(), $format->prefixes, true)) { | |
return; | |
} | |
throw new DomainException('Invalid prefix.'); | |
} | |
} |
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
<?php declare(strict_types=1); | |
final class DocumentFormatValidator | |
{ | |
private function validatePrefix(Filename $filename, DocumentFormat $format): void | |
{ | |
$detectedPrefix = $this->detectPrefix($filename); | |
if ($format->requiresPrefix()) { | |
if ($detectedPrefix === null) { | |
throw new DomainException('Missing prefix.'); | |
} | |
if (!in_array($detectedPrefix->toString(), $format->prefixes, true)) { | |
throw new DomainException('Invalid prefix.'); | |
} | |
} else if ($detectedPrefix !== null) { | |
throw new DomainException('Non required prefix detected.'); | |
} | |
} | |
} |
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
<?php declare(strict_types=1); | |
final class DocumentFormatValidator | |
{ | |
private function validatePrefix(Filename $filename, DocumentFormat $format): void | |
{ | |
$detectedPrefix = $this->detectPrefix($filename); | |
if ($format->requiresPrefix()) { | |
if ($detectedPrefix === null) { | |
throw new DomainException('Missing prefix.'); | |
} | |
if (!in_array($detectedPrefix->toString(), $format->prefixes, true)) { | |
throw new DomainException('Invalid prefix.'); | |
} | |
} else { | |
if ($detectedPrefix !== null) { | |
throw new DomainException('Non required prefix detected.'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original:
Originally my version looked similar to the others. But since I prefer "early returns" I removed any else-construct.
OpenAI:
PHPStorm PHP Inspection: