Code Duplication    Length = 34-35 lines in 2 locations

src/Notifications/NotificationFactory.php 1 location

@@ 8-42 (lines=35) @@
5
use Payment247\SDK\Exceptions\InvalidNotificationException;
6
use Payment247\SDK\Exceptions\InvalidNotificationTypeException;
7
8
class NotificationFactory
9
{
10
    /**
11
     * @param array $notification
12
     *
13
     * @throws InvalidNotificationException
14
     * @throws InvalidNotificationTypeException
15
     *
16
     * @return Notification
17
     */
18
    public function factory(array $notification)
19
    {
20
        if (empty($notification['type'])) {
21
            throw new InvalidNotificationException($notification);
22
        }
23
24
        $className = $this->getClassName($notification['type']);
25
26
        if (class_exists($className)) {
27
            return new $className($notification);
28
        }
29
30
        throw new InvalidNotificationTypeException($notification['type']);
31
    }
32
33
    /**
34
     * @param $type
35
     *
36
     * @return string
37
     */
38
    protected function getClassName($type)
39
    {
40
        return __NAMESPACE__.'\\'.str_replace('_', '', ucwords($type, '_')).'Notification';
41
    }
42
}
43

src/Responses/ResponseFactory.php 1 location

@@ 7-40 (lines=34) @@
4
5
use Payment247\SDK\Exceptions\InvalidResponseTypeException;
6
7
class ResponseFactory
8
{
9
    /**
10
     * @param array $response
11
     *
12
     * @throws InvalidResponseTypeException
13
     *
14
     * @return Response
15
     */
16
    public function factory(array $response)
17
    {
18
        if (empty($response['object'])) {
19
            return new ArrayResponse($response);
20
        }
21
22
        $className = self::getClassName($response['object']);
23
24
        if (class_exists($className)) {
25
            return new $className($response);
26
        }
27
28
        throw new InvalidResponseTypeException($response['object']);
29
    }
30
31
    /**
32
     * @param $type
33
     *
34
     * @return string
35
     */
36
    protected function getClassName($type)
37
    {
38
        return __NAMESPACE__.'\\'.str_replace('_', '', ucwords($type, '_'));
39
    }
40
}
41