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

ValidationUtils::sanitizeSecureInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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