Completed
Push — master ( 4859e1...c3d3e1 )
by
unknown
11:17
created

ValidationUtils   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A guessValidationMessagePrefix() 0 11 3
A sanitizeSecureInfo() 0 8 2
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Utils;
4
5
use OroCRM\Bundle\MagentoBundle\Entity\Order;
6
7
class ValidationUtils
8
{
9
    /**
10
     * Guess validation message prefix based on entity type
11
     *
12
     * @param object $entity
13
     *
14
     * @return string
15
     */
16
    public static function guessValidationMessagePrefix($entity)
17
    {
18
        $prefix = 'Validation error: ';
19
        if ($entity instanceof Order) {
20
            $prefix .= sprintf('Magento order #%s', $entity->getIncrementId());
21
        } elseif (method_exists($entity, 'getOriginId')) {
22
            $prefix .= sprintf('Magento entity ID %d', $entity->getOriginId());
23
        }
24
25
        return $prefix;
26
    }
27
28
    /**
29
     * Sanitise error message for secure info
30
     *
31
     * @param string
32
     *
33
     * @return string
34
     */
35
    public static function sanitizeSecureInfo($message)
36
    {
37
        if (is_string($message)) {
38
            return preg_replace('#(<apiKey.*?>)(.*)(</apiKey>)#i', '$1***$3', $message);
39
        }
40
41
        return $message;
42
    }
43
}
44