GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (3647)

symphony/lib/toolkit/class.section.php (38 issues)

1
<?php
2
3
/**
4
 * @package toolkit
5
 */
6
/**
7
 * The Section class represents a Symphony Section object. A section is a model
8
 * of a data structure using one or more Fields. Sections are stored in the database
9
 * and are used as repositories for Entry objects, which are a model for this data
10
 * structure. This class contains functions for finding Fields within a Section and
11
 * saving a Section's settings.
12
 */
13
14
class Section
15
{
16
    /**
17
     * An array of the Section's settings
18
     * @var array
19
     */
20
    protected $_data = array();
21
22
    /**
23
     * A setter function that will save a section's setting into
24
     * the poorly named `$this->_data` variable
25
     *
26
     * @param string $setting
27
     *  The setting name
28
     * @param string $value
29
     *  The setting value
30
     */
31
    public function set($setting, $value)
32
    {
33
        $this->_data[$setting] = $value;
34
    }
35
36
    /**
37
     * An accessor function for this Section's settings. If the
38
     * $setting param is omitted, an array of all settings will
39
     * be returned. Otherwise it will return the data for
40
     * the setting given.
41
     *
42
     * @param null|string $setting
43
     * @return array|string
44
     *    If setting is provided, returns a string, if setting is omitted
45
     *    returns an associative array of this Section's settings
46
     */
47
    public function get($setting = null)
0 ignored issues
show
Incorrect spacing between argument "$setting" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$setting"; expected 0 but found 1
Loading history...
48
    {
49
        if (is_null($setting)) {
50
            return $this->_data;
51
        }
52
53
        return $this->_data[$setting];
54
    }
55
56
    /**
57
     * Returns the default field this Section will be sorted by.
58
     * This is determined by the first visible field that is allowed to
59
     * to be sorted (defined by the field's `isSortable()` function).
60
     * If no fields exist or none of them are visible in the entries table,
61
     * 'id' is returned instead.
62
     *
63
     * @since Symphony 2.3
64
     * @throws Exception
65
     * @return string
66
     *    Either the field ID or the string 'id'.
67
     */
68
    public function getDefaultSortingField()
69
    {
70
        $fields = $this->fetchVisibleColumns();
71
72
        foreach ($fields as $field) {
73
            if (!$field->isSortable()) {
74
                continue;
75
            }
76
77
            return $field->get('id');
78
        }
79
80
        return 'id';
81
    }
82
83
    /**
84
     * Returns the field this Section will be sorted by, or calls
85
     * `getDefaultSortingField()` if the configuration file doesn't
86
     * contain any settings for that Section.
87
     *
88
     * @since Symphony 2.3
89
     * @throws Exception
90
     * @return string
91
     *    Either the field ID or the string 'id'.
92
     */
93
    public function getSortingField()
94
    {
95
        $result = Symphony::Configuration()->get('section_' . $this->get('handle') . '_sortby', 'sorting');
0 ignored issues
show
Are you sure $this->get('handle') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
        $result = Symphony::Configuration()->get('section_' . /** @scrutinizer ignore-type */ $this->get('handle') . '_sortby', 'sorting');
Loading history...
96
97
        return (is_null($result) ? $this->getDefaultSortingField() : $result);
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($result) ...ortingField() : $result also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
The condition is_null($result) is always false.
Loading history...
98
    }
99
100
    /**
101
     * Returns the sort order for this Section. Defaults to 'asc'.
102
     *
103
     * @since Symphony 2.3
104
     * @return string
105
     *  Either 'asc' or 'desc'.
106
     */
107
    public function getSortingOrder()
108
    {
109
        $result = Symphony::Configuration()->get('section_' . $this->get('handle') . '_order', 'sorting');
0 ignored issues
show
Are you sure $this->get('handle') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
        $result = Symphony::Configuration()->get('section_' . /** @scrutinizer ignore-type */ $this->get('handle') . '_order', 'sorting');
Loading history...
110
111
        return (is_null($result) ? 'asc' : $result);
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($result) ? 'asc' : $result also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
The condition is_null($result) is always false.
Loading history...
112
    }
113
114
    /**
115
     * Saves the new field this Section will be sorted by.
116
     *
117
     * @since Symphony 2.3
118
     * @param string $sort
119
     *  The field ID or the string 'id'.
120
     * @param boolean $write
121
     *  If false, the new settings won't be written on the configuration file.
122
     *  Defaults to true.
123
     */
124
    public function setSortingField($sort, $write = true)
0 ignored issues
show
Incorrect spacing between argument "$write" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$write"; expected 0 but found 1
Loading history...
125
    {
126
        Symphony::Configuration()->set('section_' . $this->get('handle') . '_sortby', $sort, 'sorting');
0 ignored issues
show
Are you sure $this->get('handle') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

126
        Symphony::Configuration()->set('section_' . /** @scrutinizer ignore-type */ $this->get('handle') . '_sortby', $sort, 'sorting');
Loading history...
127
128
        if ($write) {
129
            Symphony::Configuration()->write();
130
        }
131
    }
132
133
    /**
134
     * Saves the new sort order for this Section.
135
     *
136
     * @since Symphony 2.3
137
     * @param string $order
138
     *  Either 'asc' or 'desc'.
139
     * @param boolean $write
140
     *  If false, the new settings won't be written on the configuration file.
141
     *  Defaults to true.
142
     */
143
    public function setSortingOrder($order, $write = true)
0 ignored issues
show
Incorrect spacing between argument "$write" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$write"; expected 0 but found 1
Loading history...
144
    {
145
        Symphony::Configuration()->set('section_' . $this->get('handle') . '_order', $order, 'sorting');
0 ignored issues
show
Are you sure $this->get('handle') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
        Symphony::Configuration()->set('section_' . /** @scrutinizer ignore-type */ $this->get('handle') . '_order', $order, 'sorting');
Loading history...
146
147
        if ($write) {
148
            Symphony::Configuration()->write();
149
        }
150
    }
151
152
    /**
153
     * Returns any section associations this section has with other sections
154
     * linked using fields. Has an optional parameter, `$respect_visibility` that
155
     * will only return associations that are deemed visible by a field that
156
     * created the association. eg. An articles section may link to the authors
157
     * section, but the field that links these sections has hidden this association
158
     * so an Articles column will not appear on the Author's Publish Index
159
     *
160
     * @deprecated This function will be removed in Symphony 3.0. Use `SectionManager::fetchChildAssociations` instead.
161
     * @param boolean $respect_visibility
162
     *  Whether to return all the section associations regardless of if they
163
     *  are deemed visible or not. Defaults to false, which will return all
164
     *  associations.
165
     * @return array
166
     */
167
    public function fetchAssociatedSections($respect_visibility = false)
0 ignored issues
show
Incorrect spacing between argument "$respect_visibility" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$respect_visibility"; expected 0 but found 1
Loading history...
168
    {
169
        if (Symphony::Log()) {
170
            Symphony::Log()->pushDeprecateWarningToLog('Section::fetchAssociatedSections()', 'SectionManager::fetchChildAssociations()');
171
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
172
        return SectionManager::fetchChildAssociations($this->get('id'), $respect_visibility);
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of SectionManager::fetchChildAssociations(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

172
        return SectionManager::fetchChildAssociations(/** @scrutinizer ignore-type */ $this->get('id'), $respect_visibility);
Loading history...
173
    }
174
175
    /**
176
     * Returns any section associations this section has with other sections
177
     * linked using fields, and where this section is the parent in the association.
178
     * Has an optional parameter, `$respect_visibility` that
179
     * will only return associations that are deemed visible by a field that
180
     * created the association. eg. An articles section may link to the authors
181
     * section, but the field that links these sections has hidden this association
182
     * so an Articles column will not appear on the Author's Publish Index
183
     *
184
     * @since Symphony 2.3.3
185
     * @param boolean $respect_visibility
186
     *  Whether to return all the section associations regardless of if they
187
     *  are deemed visible or not. Defaults to false, which will return all
188
     *  associations.
189
     * @return array
190
     */
191
    public function fetchChildAssociations($respect_visibility = false)
0 ignored issues
show
Incorrect spacing between argument "$respect_visibility" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$respect_visibility"; expected 0 but found 1
Loading history...
192
    {
193
        return SectionManager::fetchChildAssociations($this->get('id'), $respect_visibility);
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of SectionManager::fetchChildAssociations(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

193
        return SectionManager::fetchChildAssociations(/** @scrutinizer ignore-type */ $this->get('id'), $respect_visibility);
Loading history...
194
    }
195
196
    /**
197
     * Returns any section associations this section has with other sections
198
     * linked using fields, and where this section is the child in the association.
199
     * Has an optional parameter, `$respect_visibility` that
200
     * will only return associations that are deemed visible by a field that
201
     * created the association. eg. An articles section may link to the authors
202
     * section, but the field that links these sections has hidden this association
203
     * so an Articles column will not appear on the Author's Publish Index
204
     *
205
     * @since Symphony 2.3.3
206
     * @param boolean $respect_visibility
207
     *  Whether to return all the section associations regardless of if they
208
     *  are deemed visible or not. Defaults to false, which will return all
209
     *  associations.
210
     * @return array
211
     */
212
    public function fetchParentAssociations($respect_visibility = false)
0 ignored issues
show
Incorrect spacing between argument "$respect_visibility" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$respect_visibility"; expected 0 but found 1
Loading history...
213
    {
214
        return SectionManager::fetchParentAssociations($this->get('id'), $respect_visibility);
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of SectionManager::fetchParentAssociations(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

214
        return SectionManager::fetchParentAssociations(/** @scrutinizer ignore-type */ $this->get('id'), $respect_visibility);
Loading history...
215
    }
216
217
    /**
218
     * Returns an array of all the fields in this section that are to be displayed
219
     * on the entries table page ordered by the order in which they appear
220
     * in the Section Editor interface
221
     *
222
     * @throws Exception
223
     * @return array
224
     */
225
    public function fetchVisibleColumns()
226
    {
227
        return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, null, " AND t1.show_column = 'yes' ");
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of FieldManager::fetch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

227
        return FieldManager::fetch(null, /** @scrutinizer ignore-type */ $this->get('id'), 'ASC', 'sortorder', null, null, " AND t1.show_column = 'yes' ");
Loading history...
228
    }
229
230
    /**
231
     * Returns an array of all the fields in this section optionally filtered by
232
     * the field type or it's location within the section.
233
     *
234
     * @param string $type
235
     *    The field type (it's handle as returned by `$field->handle()`)
236
     * @param string $location
237
     *    The location of the fields in the entry creator, whether they are
238
     *    'main' or 'sidebar'
239
     * @throws Exception
240
     * @return array
241
     */
242
    public function fetchFields($type = null, $location = null)
0 ignored issues
show
Incorrect spacing between argument "$type" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$type"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$location" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$location"; expected 0 but found 1
Loading history...
243
    {
244
        return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', $type, $location);
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of FieldManager::fetch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

244
        return FieldManager::fetch(null, /** @scrutinizer ignore-type */ $this->get('id'), 'ASC', 'sortorder', $type, $location);
Loading history...
245
    }
246
247
    /**
248
     * Returns an array of all the fields that can be filtered.
249
     *
250
     * @param string $location
251
     *    The location of the fields in the entry creator, whether they are
252
     *    'main' or 'sidebar'
253
     * @throws Exception
254
     * @return array
255
     */
256
    public function fetchFilterableFields($location = null)
0 ignored issues
show
Incorrect spacing between argument "$location" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$location"; expected 0 but found 1
Loading history...
257
    {
258
        return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__FILTERABLE_ONLY__);
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of FieldManager::fetch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

258
        return FieldManager::fetch(null, /** @scrutinizer ignore-type */ $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__FILTERABLE_ONLY__);
Loading history...
259
    }
260
261
    /**
262
     * Returns an array of all the fields that can be toggled. This function
263
     * is used to help build the With Selected drop downs on the Publish
264
     * Index pages
265
     *
266
     * @param string $location
267
     *    The location of the fields in the entry creator, whether they are
268
     *    'main' or 'sidebar'
269
     * @throws Exception
270
     * @return array
271
     */
272
    public function fetchToggleableFields($location = null)
0 ignored issues
show
Incorrect spacing between argument "$location" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$location"; expected 0 but found 1
Loading history...
273
    {
274
        return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__TOGGLEABLE_ONLY__);
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of FieldManager::fetch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

274
        return FieldManager::fetch(null, /** @scrutinizer ignore-type */ $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__TOGGLEABLE_ONLY__);
Loading history...
275
    }
276
277
    /**
278
     * Returns the Schema of this section which includes all this sections
279
     * fields and their settings.
280
     *
281
     * @return array
282
     */
283
    public function fetchFieldsSchema()
284
    {
285
        return FieldManager::fetchFieldsSchema($this->get('id'));
0 ignored issues
show
$this->get('id') of type array|string is incompatible with the type integer expected by parameter $section_id of FieldManager::fetchFieldsSchema(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

285
        return FieldManager::fetchFieldsSchema(/** @scrutinizer ignore-type */ $this->get('id'));
Loading history...
286
    }
287
288
    /**
289
     * Commit the settings of this section from the section editor to
290
     * create an instance of this section in `tbl_sections`. This function
291
     * loops of each of the fields in this section and calls their commit
292
     * function.
293
     *
294
     * @see toolkit.Field#commit()
295
     * @return boolean
296
     *  true if the commit was successful, false otherwise.
297
     */
298
    public function commit()
299
    {
300
        $settings = $this->_data;
301
302
        if (isset($settings['id'])) {
303
            $id = $settings['id'];
304
            unset($settings['id']);
305
            $section_id = SectionManager::edit($id, $settings);
306
307
            if ($section_id) {
308
                $section_id = $id;
309
            }
310
        } else {
311
            $section_id = SectionManager::add($settings);
312
        }
313
314
        if (is_numeric($section_id) && $section_id !== false) {
315
            for ($ii = 0, $length = count($this->_fields); $ii < $length; $ii++) {
0 ignored issues
show
Bug Best Practice introduced by
The property _fields does not exist on Section. Did you maybe forget to declare it?
Loading history...
316
                $this->_fields[$ii]->set('parent_section', $section_id);
317
                $this->_fields[$ii]->commit();
318
            }
319
        }
320
    }
321
}
322