NegotiateTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B negotiateHeader() 0 16 5
1
<?php
2
3
namespace Psr7Middlewares\Utils;
4
5
use Negotiation\AbstractNegotiator;
6
7
/**
8
 * Utilities used by middlewares that use a negotiator.
9
 */
10
trait NegotiateTrait
11
{
12
    /**
13
     * Returns the best value of a header.
14
     *
15
     * @param string             $accept     The header to negotiate
16
     * @param AbstractNegotiator $negotiator
17
     * @param array              $priorities
18
     *
19
     * @return string|null
20
     */
21
    private function negotiateHeader($accept, AbstractNegotiator $negotiator, array $priorities)
22
    {
23
        if (empty($accept) || empty($priorities)) {
24
            return;
25
        }
26
27
        try {
28
            $best = $negotiator->getBest($accept, $priorities);
29
        } catch (\Exception $exception) {
30
            return;
31
        }
32
33
        if ($best) {
34
            return $best->getValue();
35
        }
36
    }
37
}
38