RestfulServerTestValidationFailure::canCreate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SilverStripe\RestfulServer\Tests\Stubs;
4
5
use SilverStripe\Dev\TestOnly;
6
use SilverStripe\ORM\DataObject;
7
8
/**
9
 * Class RestfulServerTestValidationFailure
10
 * @package SilverStripe\RestfulServer\Tests\Stubs
11
 *
12
 * @property string Content
13
 * @property string Title
14
 */
15
class RestfulServerTestValidationFailure extends DataObject implements TestOnly
16
{
17
    private static $api_access = true;
0 ignored issues
show
introduced by
The private property $api_access is not used, and could be removed.
Loading history...
18
19
    private static $table_name = 'RestfulServerTestValidationFailure';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
20
21
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
22
        'Content' => 'Text',
23
        'Title' => 'Text',
24
    );
25
26
    /**
27
     * @return \SilverStripe\ORM\ValidationResult
28
     */
29
    public function validate()
30
    {
31
        $result = parent::validate();
32
33
        if (strlen($this->Content) === 0) {
34
            $result->addFieldError('Content', 'Content required');
35
        }
36
37
        if (strlen($this->Title) === 0) {
38
            $result->addFieldError('Title', 'Title required');
39
        }
40
41
        return $result;
42
    }
43
44
    public function canView($member = null)
45
    {
46
        return true;
47
    }
48
49
    public function canEdit($member = null)
50
    {
51
        return true;
52
    }
53
54
    public function canDelete($member = null)
55
    {
56
        return true;
57
    }
58
59
    public function canCreate($member = null, $context = array())
60
    {
61
        return true;
62
    }
63
}
64