-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor solution to use SplFileObject
Which is simpler and doesn't require the use of the `@` operator.
- Loading branch information
Showing
1 changed file
with
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
|
||
namespace Lcobucci\JWT\Signer; | ||
|
||
use Exception; | ||
use InvalidArgumentException; | ||
use SplFileObject; | ||
|
||
/** | ||
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> | ||
|
@@ -58,18 +60,13 @@ private function setContent($content) | |
*/ | ||
private function readFile($content) | ||
{ | ||
$file = substr($content, 7); | ||
try { | ||
$file = new SplFileObject(substr($content, 7)); | ||
|
||
if (!is_readable($file)) { | ||
throw new InvalidArgumentException('You must inform a valid key file'); | ||
return $file->fread($file->getSize()); | ||
} catch (Exception $exception) { | ||
throw new InvalidArgumentException('You must inform a valid key file', 0, $exception); | ||
} | ||
|
||
$content = @file_get_contents($file); | ||
if ($content === false) { | ||
throw new InvalidArgumentException('You must inform a valid key file'); | ||
} | ||
|
||
return $content; | ||
} | ||
|
||
/** | ||
|