3
3
namespace DivineOmega \PasswordExposed ;
4
4
5
5
use Psr \Cache \CacheItemPoolInterface ;
6
- use Psr \Cache \InvalidArgumentException ;
7
6
use Psr \Http \Client \ClientExceptionInterface ;
8
7
use Psr \Http \Client \ClientInterface ;
9
8
use Psr \Http \Message \RequestFactoryInterface ;
10
9
use Psr \Http \Message \ResponseInterface ;
11
10
use Psr \Http \Message \UriFactoryInterface ;
12
11
13
12
/**
14
- * Class AbstractPasswordExposedChecker
13
+ * Class AbstractPasswordExposedChecker.
15
14
*/
16
15
abstract class AbstractPasswordExposedChecker implements PasswordExposedCheckerInterface
17
16
{
@@ -33,7 +32,7 @@ public function passwordExposed(string $password): string
33
32
public function passwordExposedByHash (string $ hash ): string
34
33
{
35
34
$ cache = $ this ->getCache ();
36
- $ cacheKey = substr ($ hash , 0 , 2 ) . '_ ' . substr ($ hash , 2 , 3 );
35
+ $ cacheKey = substr ($ hash , 0 , 2 ). '_ ' . substr ($ hash , 2 , 3 );
37
36
$ body = null ;
38
37
39
38
try {
@@ -43,7 +42,7 @@ public function passwordExposedByHash(string $hash): string
43
42
if ($ cacheItem ->isHit ()) {
44
43
$ body = $ cacheItem ->get ();
45
44
}
46
- } catch (InvalidArgumentException $ e ) {
45
+ } catch (\ Exception $ e ) {
47
46
$ cacheItem = null ;
48
47
}
49
48
@@ -108,12 +107,13 @@ public function isExposedByHash(string $hash): ?bool
108
107
/**
109
108
* @param $hash
110
109
*
111
- * @return ResponseInterface
112
110
* @throws \Psr\Http\Client\ClientExceptionInterface
111
+ *
112
+ * @return ResponseInterface
113
113
*/
114
114
protected function makeRequest (string $ hash ): ResponseInterface
115
115
{
116
- $ uri = $ this ->getUriFactory ()->createUri ('https://api.pwnedpasswords.com/range/ ' . substr ($ hash , 0 , 5 ));
116
+ $ uri = $ this ->getUriFactory ()->createUri ('https://api.pwnedpasswords.com/range/ ' . substr ($ hash , 0 , 5 ));
117
117
$ request = $ this ->getRequestFactory ()->createRequest ('GET ' , $ uri );
118
118
119
119
return $ this ->getClient ()->sendRequest ($ request );
0 commit comments