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 | |
class XYZ { | |
// ... | |
public function openForRead($id) | |
{ | |
return @fopen($id, 'r'); | |
} | |
} |
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 | |
class XYZ { | |
// ... | |
public static function openForRead(string $id): ?resouce | |
{ | |
$resource = @fopen($id, 'r'); | |
return $resource ? $resource : null; | |
} | |
} |
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 | |
class XYZ { | |
// ... | |
public static function openForRead(string $id): ?SplFileObject | |
{ | |
$fileInfo = new SplFileInfo($id); | |
try { | |
return $fileInfo->openFile('r'); | |
} catch (\Exception $e) { | |
return null; |
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 | |
try { | |
$loanSchedule = $calculator->calculate($loanDeptorRequest); | |
} catch (CalculatorException $e) { | |
// log the event or sth else | |
} |
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 | |
//.... | |
$action = DocumentSigningAction::create($doc); | |
/** @var \Psr\Http\Message\ResponseInterface $response */ | |
$response = $action->execute(); | |
if ($response->getStatusCode() !== 200) { | |
throw new SigningException("Could not sign document"); | |
} |
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 | |
//.... | |
$action = DocumentSigningAction::create($doc); | |
/** @var \Psr\Http\Message\ResponseInterface $response */ | |
$response = $action->execute(); | |
if ($response->getStatusCode() >= 500) { | |
throw new SigningServiceUnavailable(); | |
} |
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 | |
if ($response->getStatusCode() >= 400) { | |
$code = $this->extractErrorCode($response->getBody()); | |
switch ($code) { | |
case FailReasons::NO_TAGS: | |
$msg = 'The document has not enough signature tags'; | |
break; | |
//... |
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 | |
final class ResultObject | |
{ | |
public $isSuccessful; | |
public $payload = null; | |
private function __construct(bool $isSuccessful, $payload = null) | |
{ | |
$this->isSuccessful = $isSuccessful; | |
$this->payload = $payload; |
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 | |
$handler = @fopen(join(DIRECTORY_SEPARATOR, [__DIR__, 'credit_cards.txt']), "r"); | |
if ($handler) { | |
return CreditCardNumberExtractor::createFromHandler($handler); | |
} | |
/* ... */ |
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 | |
$operation = File::openForRead(join(DIRECTORY_SEPARATOR, [__DIR__, 'credit_cards.txt'])); | |
if ($operation->isSuccessful) { | |
return CreditCardNumberExtractor::createFromHandler($operation->payload); | |
} | |
/* ... */ |
OlderNewer