Code Duplication    Length = 18-18 lines in 2 locations

src/Middleware/FormTimestamp.php 1 location

@@ 94-111 (lines=18) @@
91
     *
92
     * @return ResponseInterface
93
     */
94
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
95
    {
96
        if (!Middleware::hasAttribute($request, FormatNegotiator::KEY)) {
97
            throw new RuntimeException('FormTimestamp middleware needs FormatNegotiator executed before');
98
        }
99
100
        if (FormatNegotiator::getFormat($request) !== 'html') {
101
            return $next($request, $response);
102
        }
103
104
        if ($this->isPost($request) && !$this->isValid($request)) {
105
            return $response->withStatus(403);
106
        }
107
108
        $response = $next($request, $response);
109
110
        return $this->insertIntoPostForms($response, '<input type="hidden" name="'.$this->inputName.'" value="'.$this->encrypt(time()).'">');
111
    }
112
113
    /**
114
     * Check whether the request is valid.

src/Middleware/Honeypot.php 1 location

@@ 64-81 (lines=18) @@
61
     *
62
     * @return ResponseInterface
63
     */
64
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
65
    {
66
        if (!Middleware::hasAttribute($request, FormatNegotiator::KEY)) {
67
            throw new RuntimeException('Honeypot middleware needs FormatNegotiator executed before');
68
        }
69
70
        if (FormatNegotiator::getFormat($request) !== 'html') {
71
            return $next($request, $response);
72
        }
73
74
        if ($this->isPost($request) && !$this->isValid($request)) {
75
            return $response->withStatus(403);
76
        }
77
78
        $response = $next($request, $response);
79
80
        return $this->insertIntoPostForms($response, '<input type="text" name="'.$this->inputName.'" class="'.$this->inputClass.'">');
81
    }
82
83
    /**
84
     * Check whether the request is valid.