Passed
Push — 4-cactus ( ef482b...a29fed )
by Stefano
03:29
created

Profile::_setWebsite()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 3
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2016 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
14
namespace BEdita\Core\Model\Entity;
15
16
use Cake\Validation\Validation;
17
18
/**
19
 * Profile Entity.
20
 *
21
 * @property int $id
22
 * @property string $name
23
 * @property string $surname
24
 * @property string $email
25
 * @property string $person_title
26
 * @property string $gender
27
 * @property \Cake\I18n\Time $birthdate
28
 * @property \Cake\I18n\Time $deathdate
29
 * @property bool $company
30
 * @property string $company_name
31
 * @property string $company_kind
32
 * @property string $street_address
33
 * @property string $city
34
 * @property string $zipcode
35
 * @property string $country
36
 * @property string $state_name
37
 * @property string $phone
38
 * @property string $website
39
 * @property string $national_id_number
40
 * @property string $vat_number
41
 * @property string $pseudonym
42
 * @since 4.0.0
43
 */
44
class Profile extends ObjectEntity
45
{
46
    /**
47
     * Ensure URL is standardized by prefixing `http://` to it if necessary.
48
     *
49
     * @param mixed $website Website URL.
50
     * @return mixed
51
     */
52
    protected function _setWebsite($website)
53
    {
54
        if (is_string($website) && Validation::url($website, false) && !Validation::url($website, true)) {
55
            return sprintf('http://%s', $website);
56
        }
57
58
        // By returning the original value instead of `null` when an invalid URL is encountered, we preserve validation errors.
59
        return $website;
60
    }
61
}
62