Passed
Push — master ( 8dcc68...34e8da )
by
unknown
23:44 queued 20:40
created

SyncTaskRecurrence::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 95
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 45
nc 4
nop 0
dl 0
loc 95
rs 9.2
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * SPDX-License-Identifier: AGPL-3.0-only
4
 * SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH
5
 * SPDX-FileCopyrightText: Copyright 2020-2022 grommunio GmbH
6
 *
7
 * WBXML task recurrence entities that can be parsed directly (as a stream)
8
 * from WBXML. It is automatically decoded according to $mapping and the Sync
9
 * WBXML mappings.
10
 */
11
12
// Exactly the same as SyncRecurrence, but then with SYNC_POOMTASKS_*
13
class SyncTaskRecurrence extends SyncObject {
14
    public $start;
15
    public $type;
16
    public $until;
17
    public $occurrences;
18
    public $interval;
19
    public $dayofweek;
20
    public $dayofmonth;
21
    public $weekofmonth;
22
    public $monthofyear;
23
    public $regenerate;
24
    public $deadoccur;
25
    public $calendartype;
26
    public $firstdayofweek;
27
28
    function __construct() {
29
        $mapping = array (
30
                    SYNC_POOMTASKS_START                                => array (  self::STREAMER_VAR      => "start",
31
                                                                                    self::STREAMER_TYPE     => self::STREAMER_TYPE_DATE,
32
                                                                                    self::STREAMER_RONOTIFY => true),
33
34
                    // Recurrence type
35
                    // 0 = Recurs daily
36
                    // 1 = Recurs weekly
37
                    // 2 = Recurs monthly
38
                    // 3 = Recurs monthly on the nth day
39
                    // 5 = Recurs yearly
40
                    // 6 = Recurs yearly on the nth day
41
                    SYNC_POOMTASKS_TYPE                                 => array (  self::STREAMER_VAR      => "type",
42
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_REQUIRED   => self::STREAMER_CHECK_SETZERO,
43
                                                                                                                        self::STREAMER_CHECK_ONEVALUEOF => array(0,1,2,3,5,6) ),
44
                                                                                    self::STREAMER_RONOTIFY => true),
45
46
                    SYNC_POOMTASKS_UNTIL                                => array (  self::STREAMER_VAR      => "until",
47
                                                                                    self::STREAMER_TYPE     => self::STREAMER_TYPE_DATE,
48
                                                                                    self::STREAMER_RONOTIFY => true),
49
50
                    SYNC_POOMTASKS_OCCURRENCES                          => array (  self::STREAMER_VAR      => "occurrences",
51
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_CMPHIGHER  => 0,
52
                                                                                                                        self::STREAMER_CHECK_CMPLOWER   => 1000 ),
53
                                                                                    self::STREAMER_RONOTIFY => true),
54
55
                    SYNC_POOMTASKS_INTERVAL                             => array (  self::STREAMER_VAR      => "interval",
56
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_CMPHIGHER  => 0,
57
                                                                                                                        self::STREAMER_CHECK_CMPLOWER   => 1000 ),
58
                                                                                    self::STREAMER_RONOTIFY => true),
59
60
                    //TODO: check iOS5 sends deadoccur inside of the recurrence
61
                    SYNC_POOMTASKS_DEADOCCUR                            => array (  self::STREAMER_VAR      => "deadoccur",
62
                                                                                    self::STREAMER_RONOTIFY => true),
63
                    SYNC_POOMTASKS_REGENERATE                           => array (  self::STREAMER_VAR      => "regenerate",
64
                                                                                    self::STREAMER_RONOTIFY => true),
65
66
                    // DayOfWeek values
67
                    //   1 = Sunday
68
                    //   2 = Monday
69
                    //   4 = Tuesday
70
                    //   8 = Wednesday
71
                    //  16 = Thursday
72
                    //  32 = Friday
73
                    //  62 = Weekdays  // TODO check: value set by WA with daily weekday recurrence
74
                    //  64 = Saturday
75
                    // 127 = The last day of the month. Value valid only in monthly or yearly recurrences.
76
                    SYNC_POOMTASKS_DAYOFWEEK                            => array (  self::STREAMER_VAR      => "dayofweek",
77
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_CMPHIGHER  => 0,
78
                                                                                                                        self::STREAMER_CHECK_CMPLOWER   => 128 ),
79
                                                                                    self::STREAMER_RONOTIFY => true),
80
81
                    // DayOfMonth values
82
                    // 1-31 representing the day
83
                    SYNC_POOMTASKS_DAYOFMONTH                           => array (  self::STREAMER_VAR      => "dayofmonth",
84
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_CMPHIGHER  => 0,
85
                                                                                                                        self::STREAMER_CHECK_CMPLOWER   => 32 ),
86
                                                                                    self::STREAMER_RONOTIFY => true),
87
88
                    // WeekOfMonth
89
                    // 1-4 = Y st/nd/rd/th week of month
90
                    // 5 = last week of month
91
                    SYNC_POOMTASKS_WEEKOFMONTH                          => array (  self::STREAMER_VAR      => "weekofmonth",
92
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_ONEVALUEOF => array(1,2,3,4,5) ),
93
                                                                                    self::STREAMER_RONOTIFY => true),
94
95
                    // MonthOfYear
96
                    // 1-12 representing the month
97
                    SYNC_POOMTASKS_MONTHOFYEAR                          => array (  self::STREAMER_VAR      => "monthofyear",
98
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_ONEVALUEOF => array(1,2,3,4,5,6,7,8,9,10,11,12) ),
99
                                                                                    self::STREAMER_RONOTIFY => true),
100
                );
101
102
        if(Request::GetProtocolVersion() >= 14.0) {
103
            $mapping[SYNC_POOMTASKS_CALENDARTYPE]                       = array (   self::STREAMER_VAR      => "calendartype",
104
                                                                                    self::STREAMER_RONOTIFY => true);
105
        }
106
107
        if(Request::GetProtocolVersion() >= 14.1) {
108
            // First day of the calendar week for recurrence.
109
            // FirstDayOfWeek values:
110
            //   0 = Sunday
111
            //   1 = Monday
112
            //   2 = Tuesday
113
            //   3 = Wednesday
114
            //   4 = Thursday
115
            //   5 = Friday
116
            //   6 = Saturday
117
            $mapping[SYNC_POOMTASKS_FIRSTDAYOFWEEK]                     = array (   self::STREAMER_VAR      => "firstdayofweek",
118
                                                                                    self::STREAMER_CHECKS   => array(   self::STREAMER_CHECK_ONEVALUEOF => array(0,1,2,3,4,5,6) ),
119
                                                                                    self::STREAMER_RONOTIFY => true);
120
        }
121
122
        parent::__construct($mapping);
123
    }
124
125
    /**
126
     * Method checks if the object has the minimum of required parameters
127
     * and fulfills semantic dependencies
128
     *
129
     * This overloads the general check() with special checks to be executed
130
     *
131
     * @param boolean   $logAsDebug     (opt) default is false, so messages are logged in WARN log level
132
     *
133
     * @access public
134
     * @return boolean
135
     */
136
    public function Check($logAsDebug = false) {
137
        $ret = parent::Check($logAsDebug);
138
139
        // semantic checks general "turn off switch"
140
        if (defined("DO_SEMANTIC_CHECKS") && DO_SEMANTIC_CHECKS === false)
0 ignored issues
show
Bug introduced by
The constant DO_SEMANTIC_CHECKS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
141
            return $ret;
142
143
        if (!$ret)
144
            return false;
145
146
        if (isset($this->start) && isset($this->until) && $this->until < $this->start) {
147
            ZLog::Write(LOGLEVEL_WARN, sprintf("SyncObject->Check(): Unmet condition in object from type %s: parameter 'start' is HIGHER than 'until'. Check failed!", get_class($this) ));
148
            return false;
149
        }
150
151
        return true;
152
    }
153
}
154