Passed
Pull Request — master (#214)
by Ralf
11:24
created

DocumentVoter::canEditAnonymously()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 1
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
namespace EWW\Dpf\Security;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use EWW\Dpf\Domain\Model\Document;
18
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
19
use TYPO3\CMS\Extbase\Object\ObjectManager;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use EWW\Dpf\Domain\Repository\DocumentRepository;
22
use TYPO3\CMS\Core\Log\LogManager;
23
24
25
class DocumentVoter extends Voter
26
{
27
    const CREATE = "DOCUMENT_CREATE";
28
    const CREATE_ANONYMOUSLY = "DOCUMENT_CREATE_ANONYMOUSLY";
29
    const UPDATE = "DOCUMENT_UPDATE";
30
    const LIST = "DOCUMENT_LIST";
31
    const LIST_REGISTERED = "DOCUMENT_LIST_REGISTERED";
32
    const LIST_IN_PROGRESS = "DOCUMENT_LIST_IN_PROGRESS";
33
34
    const DISCARD = "DOCUMENT_DISCARD";
35
36
    const DELETE_LOCALLY = "DOCUMENT_DELETE_LOCALLY";
37
    const DELETE_WORKING_COPY = "DOCUMENT_DELETE_WORKING_COPY";
38
    const DUPLICATE = "DOCUMENT_DUPLICATE";
39
    const RELEASE_PUBLISH = "DOCUMENT_RELEASE_PUBLISH";
40
    const RELEASE_ACTIVATE = "DOCUMENT_RELEASE_ACTIVATE";
41
    const REGISTER = "DOCUMENT_REGISTER";
42
    const SHOW_DETAILS = "DOCUMENT_SHOW_DETAILS";
43
    const CANCEL_LIST_TASK = "DOCUMENT_CANCEL_LIST_TASK";
44
    const UPLOAD_FILES = "DOCUMENT_UPLOAD_FILES";
45
    const EDIT = "DOCUMENT_EDIT";
46
    const POSTPONE = "DOCUMENT_POSTPONE";
47
    const DOUBLET_CHECK = "DOCUMENT_DOUBLET_CHECK";
48
    const SUGGEST_RESTORE = "DOCUMENT_SUGGEST_RESTORE";
49
    const SUGGEST_MODIFICATION = "DOCUMENT_SUGGEST_MODIFICATION";
50
    const SUGGESTION_ACCEPT = "DOCUMENT_SUGGESTION_ACCEPT";
51
    const EDIT_ANONYMOUSLY = "DOCUMENT_EDIT_ANONYMOUSLY";
52
    const REGISTER_ANONYMOUSLY = "DOCUMENT_REGISTER_ANONYMOUSLY";
53
    const DELETE_ANONYMOUSLY = "DOCUMENT_DELETE_ANONYMOUSLY";
54
55
    /**
56
     * editingLockService
57
     *
58
     * @var \EWW\Dpf\Services\Document\EditingLockService
59
     * @TYPO3\CMS\Extbase\Annotation\Inject
60
     */
61
    protected $editingLockService = null;
62
63
    /**
64
     * workflow
65
     *
66
     * @var DocumentWorkflow
67
     */
68
    protected $workflow;
69
70
    public function __construct()
71
    {
72
       $this->workflow = DocumentWorkflow::getWorkflow();
0 ignored issues
show
Documentation Bug introduced by
It seems like EWW\Dpf\Domain\Workflow\...Workflow::getWorkflow() of type Symfony\Component\Workflow\Workflow is incompatible with the declared type EWW\Dpf\Domain\Workflow\DocumentWorkflow of property $workflow.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
    }
74
75
76
    /**
77
     * Returns all supported attributes.
78
     *
79
     * @return array
80
     */
81
    protected static function getAttributes()
82
    {
83
        return array(
84
            self::CREATE,
85
            self::CREATE_ANONYMOUSLY,
86
            self::UPDATE,
87
            self::LIST,
88
            self::LIST_REGISTERED,
89
            self::LIST_IN_PROGRESS,
90
            self::DISCARD,
91
            self::DELETE_LOCALLY,
92
            self::DELETE_WORKING_COPY,
93
            self::DUPLICATE,
94
            self::RELEASE_PUBLISH,
95
            self::RELEASE_ACTIVATE,
96
            self::REGISTER,
97
            self::SHOW_DETAILS,
98
            self::CANCEL_LIST_TASK,
99
            self::UPLOAD_FILES,
100
            self::EDIT,
101
            self::POSTPONE,
102
            self::DOUBLET_CHECK,
103
            self::SUGGEST_RESTORE,
104
            self::SUGGEST_MODIFICATION,
105
            self::SUGGESTION_ACCEPT,
106
            self::EDIT_ANONYMOUSLY,
107
            self::REGISTER_ANONYMOUSLY,
108
            self::DELETE_ANONYMOUSLY
109
        );
110
    }
111
112
113
    /**
114
     * Determines if the voter supports the given attribute.
115
     *
116
     * @param string $attribute
117
     * @param mixed $subject
118
     * @return mixed
119
     */
120
    public static function supports($attribute, $subject = NULL)
121
    {
122
        if (!in_array($attribute, self::getAttributes())) {
123
            return FALSE;
124
        }
125
126
        if (!$subject instanceof Document && !is_null($subject)) {
127
            return FALSE;
128
        }
129
130
        return TRUE;
131
    }
132
133
    /**
134
     * Determines if access for the given attribute and subject is allowed.
135
     *
136
     * @param string $attribute
137
     * @param mixed $subject
138
     * @return mixed
139
     */
140
    public function voteOnAttribute($attribute, $subject = NULL)
141
    {
142
        if (!$subject instanceof Document) {
143
            return FALSE;
144
        }
145
146
        switch ($attribute) {
147
148
            case self::CREATE:
149
                return $this->defaultAccess($subject);
0 ignored issues
show
Unused Code introduced by
The call to EWW\Dpf\Security\DocumentVoter::defaultAccess() has too many arguments starting with $subject. ( Ignorable by Annotation )

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

149
                return $this->/** @scrutinizer ignore-call */ defaultAccess($subject);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
150
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
151
152
            case self::CREATE_ANONYMOUSLY:
153
                return $this->canCreateAnonymously($subject);
154
                break;
155
156
            case self::UPDATE:
157
                return $this->canUpdate($subject);
158
                break;
159
160
            case self::LIST:
161
                return $this->defaultAccess();
162
                break;
163
164
            case self::LIST_REGISTERED:
165
                return $this->defaultAccess();
166
                break;
167
168
            case self::LIST_IN_PROGRESS:
169
                return $this->defaultAccess();
170
                break;
171
172
            case self::DISCARD:
173
                return $this->canDiscard($subject);
174
                break;
175
176
            case self::DELETE_LOCALLY:
177
                return $this->canDeleteLocally($subject);
178
                break;
179
180
            case self::DELETE_WORKING_COPY:
181
                return $this->canDeleteWorkingCopy($subject);
182
                break;
183
184
            case self::DUPLICATE:
185
                return $this->canDuplicate($subject);
186
                break;
187
188
            case self::RELEASE_PUBLISH:
189
                return $this->canReleasePublish($subject);
190
                break;
191
192
            case self::RELEASE_ACTIVATE:
193
                return $this->canReleaseActivate($subject);
194
                break;
195
196
            case self::REGISTER:
197
                return $this->canRegister($subject);
198
                break;
199
200
            case self::SHOW_DETAILS:
201
                return $this->canShowDetails($subject);
202
203
            case self::EDIT_ANONYMOUSLY:
204
                return $this->canEditAnonymously($subject);
205
                break;
206
207
            case self::CANCEL_LIST_TASK:
208
                return $this->defaultAccess();
209
                break;
210
211
            case self::UPLOAD_FILES:
212
                return $this->canUpdate($subject);
213
                break;
214
215
            case self::EDIT:
216
                return $this->canEdit($subject);
217
                break;
218
219
            case self::POSTPONE:
220
                return $this->canPostpone($subject);
221
                break;
222
223
            case self::DOUBLET_CHECK:
224
                return $this->librarianOnly();
225
                break;
226
227
            case self::SUGGEST_RESTORE:
228
                return $this->canSuggestRestore($subject);
229
                break;
230
231
            case self::SUGGEST_MODIFICATION:
232
                return $this->canSuggestModification($subject);
233
                break;
234
235
            case self::SUGGESTION_ACCEPT:
236
                return $this->canSuggestionAccept($subject);
237
                break;
238
239
            case self::REGISTER_ANONYMOUSLY:
240
                return $this->canRegisterAnonymously($subject);
241
                break;
242
243
            case self::DELETE_ANONYMOUSLY:
244
                return $this->canEditAnonymously($subject);
245
                break;
246
        }
247
248
        /** @var $logger \TYPO3\CMS\Core\Log\Logger */
249
        $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
250
        $logger->warning('DocumentVoter::voteOnAttribute(): Unknown attribute. This code should not be reached!',
251
            [
252
                'attribute' => $attribute
253
            ]
254
        );
255
256
        return false;
257
    }
258
259
    /**
260
     * @return bool
261
     */
262
    protected function defaultAccess()
263
    {
264
        return (
265
            $this->security->getUserRole() === Security::ROLE_LIBRARIAN ||
266
            $this->security->getUserRole() === Security::ROLE_RESEARCHER
267
        );
268
    }
269
270
    /**
271
     * @return bool
272
     */
273
    protected function librarianOnly()
274
    {
275
        return $this->security->getUserRole() === Security::ROLE_LIBRARIAN;
276
    }
277
278
    /**
279
     * @param \EWW\Dpf\Domain\Model\Document $document
280
     * @return bool
281
     */
282
    protected function canDiscard($document)
283
    {
284
        if ($this->isDocumentLocked($document)) {
285
            return FALSE;
286
        }
287
288
        if ($this->workflow->can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_DISCARD)) {
0 ignored issues
show
Bug introduced by
The method can() does not exist on EWW\Dpf\Domain\Workflow\DocumentWorkflow. ( Ignorable by Annotation )

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

288
        if ($this->workflow->/** @scrutinizer ignore-call */ can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_DISCARD)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
289
            return (
290
                $this->security->getUserRole() === Security::ROLE_LIBRARIAN ||
291
                (
292
                    $document->getCreator() === $this->security->getUser()->getUid() &&
293
                    $document->getState() === DocumentWorkflow::STATE_REGISTERED_NONE
294
                )
295
            );
296
297
        }
298
299
        return FALSE;
300
    }
301
302
    /**
303
     * @param \EWW\Dpf\Domain\Model\Document $document
304
     * @return bool
305
     */
306
    protected function canShowDetails($document)
307
    {
308
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
309
            return (
310
                $document->getState() !== DocumentWorkflow::STATE_NEW_NONE ||
311
                $document->getCreator() === $this->security->getUser()->getUid()
312
            );
313
        }
314
315
        if ($this->security->getUserRole() === Security::ROLE_RESEARCHER) {
316
            return (
317
                $document->getCreator() === $this->security->getUser()->getUid() ||
318
                (
319
                    $document->getState() !== DocumentWorkflow::STATE_NEW_NONE &&
320
                    $document->getState() !== DocumentWorkflow::STATE_DISCARDED_NONE &&
321
                    $document->getState() !== DocumentWorkflow::STATE_NONE_DELETED
322
                )
323
            );
324
        }
325
326
        return FALSE;
327
    }
328
329
    /**
330
     * @param \EWW\Dpf\Domain\Model\Document $document
331
     * @return bool
332
     */
333
    protected function canRegister($document)
334
    {
335
        if (
336
            $this->workflow->can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_REGISTER) &&
337
            $document->getCreator() === $this->security->getUser()->getUid()
338
        ) {
339
           return TRUE;
340
        }
341
342
        return FALSE;
343
    }
344
345
346
    /**
347
     * @param \EWW\Dpf\Domain\Model\Document $document
348
     * @return bool
349
     */
350
    protected function canReleasePublish($document)
351
    {
352
        if ($this->isDocumentLocked($document)) {
353
            return FALSE;
354
        }
355
356
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
357
            return $this->workflow->can($document,
358
                \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_RELEASE_PUBLISH);
359
        }
360
361
        return FALSE;
362
    }
363
364
365
    /**
366
     * @param \EWW\Dpf\Domain\Model\Document $document
367
     * @return bool
368
     */
369
    protected function canReleaseActivate($document)
370
    {
371
        if ($this->isDocumentLocked($document)) {
372
            return FALSE;
373
        }
374
375
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
376
            return $this->workflow->can($document,
377
                \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE);
378
        }
379
380
        return FALSE;
381
    }
382
383
    /**
384
     * @param \EWW\Dpf\Domain\Model\Document $document
385
     * @return bool
386
     */
387
    protected function canDeleteLocally($document)
388
    {
389
        if ($this->isDocumentLocked($document)) {
390
            return FALSE;
391
        }
392
393
        if ($document->isSuggestion()) {
394
            return $this->security->getUserRole() === Security::ROLE_LIBRARIAN;
395
        }
396
397
        if ($this->workflow->can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_DELETE_LOCALLY)) {
398
            return $document->getCreator() === $this->security->getUser()->getUid();
399
        }
400
401
        if ($this->workflow->can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_DELETE_DISCARDED)) {
402
            return $this->security->getUserRole() === Security::ROLE_LIBRARIAN;
403
        }
404
405
        return FALSE;
406
    }
407
408
409
    /**
410
     * @param \EWW\Dpf\Domain\Model\Document $document
411
     * @return bool
412
     */
413
    protected function canDeleteWorkingCopy($document)
414
    {
415
        if ($document->isTemporary() || $this->isDocumentLocked($document)) {
416
            return FALSE;
417
        }
418
419
        if ($this->workflow->can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_DELETE_WORKING_COPY)) {
420
            return $this->security->getUserRole() === Security::ROLE_LIBRARIAN;
421
        }
422
423
        return FALSE;
424
    }
425
426
427
    /**
428
     * @param \EWW\Dpf\Domain\Model\Document $document
429
     * @return bool
430
     */
431
    protected function canEdit($document)
432
    {
433
        if ($this->isDocumentLocked($document)) {
434
            return FALSE;
435
        }
436
437
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
438
            return (
439
                $document->getState() !== DocumentWorkflow::STATE_NEW_NONE ||
440
                $document->getCreator() === $this->security->getUser()->getUid()
441
            );
442
        }
443
444
        if ($document->getCreator() === $this->security->getUser()->getUid()) {
445
            return (
446
                $document->getState() === DocumentWorkflow::STATE_NEW_NONE ||
447
                $document->getState() === DocumentWorkflow::STATE_REGISTERED_NONE
448
            );
449
        }
450
451
        return FALSE;
452
    }
453
454
455
    /**
456
     * @param \EWW\Dpf\Domain\Model\Document $document
457
     * @return bool
458
     */
459
    protected function canUpdate($document)
460
    {
461
        if ($this->isDocumentLocked($document)) {
462
            return FALSE;
463
        }
464
465
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
466
            return (
467
                $document->getState() !== DocumentWorkflow::STATE_NEW_NONE ||
468
                $document->getCreator() === $this->security->getUser()->getUid()
469
            );
470
        }
471
472
473
        if ($document->getCreator() === $this->security->getUser()->getUid()) {
474
            return (
475
                $document->getState() === DocumentWorkflow::STATE_NEW_NONE ||
476
                $document->getState() === DocumentWorkflow::STATE_REGISTERED_NONE
477
            );
478
        }
479
480
        return false;
481
    }
482
483
    /**
484
     * @param \EWW\Dpf\Domain\Model\Document $document
485
     * @return bool
486
     */
487
    protected function canSuggestRestore($document)
488
    {
489
        if ($this->security->getUserRole() === Security::ROLE_RESEARCHER) {
490
491
            $objectManager =GeneralUtility::makeInstance(ObjectManager::class);
492
            $documentRepository = $objectManager->get(DocumentRepository::class);
493
494
            $linkedDocument = $documentRepository->findOneByLinkedUid($document->getUid());
495
496
            if (!$linkedDocument && $document->getObjectIdentifier()) {
497
                $linkedDocument = $documentRepository->findOneByLinkedUid($document->getObjectIdentifier());
498
            }
499
500
            return (
501
                $document->getState() === DocumentWorkflow::STATE_DISCARDED_NONE ||
502
                $document->getState() === DocumentWorkflow::STATE_NONE_DELETED
503
            ) && !$linkedDocument;
504
        }
505
506
        return FALSE;
507
    }
508
509
    /**
510
     * @param \EWW\Dpf\Domain\Model\Document $document
511
     * @return bool
512
     */
513
    protected function canSuggestModification($document)
514
    {
515
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
516
        $documentRepository = $objectManager->get(DocumentRepository::class);
517
518
        $linkedDocument = $documentRepository->findOneByLinkedUid($document->getUid());
519
        if (!$linkedDocument && $document->getObjectIdentifier()) {
520
            $linkedDocument = $documentRepository->findOneByLinkedUid($document->getObjectIdentifier());
521
        }
522
523
        if ($this->security->getUserRole() === Security::ROLE_RESEARCHER) {
524
            return (
525
                (
526
                    $document->getCreator() !== $this->security->getUser()->getUid() &&
527
                    $document->getState() === DocumentWorkflow::STATE_REGISTERED_NONE
528
                ) ||
529
                (
530
                    $document->getState() !== DocumentWorkflow::STATE_NEW_NONE &&
531
                    $document->getState() !== DocumentWorkflow::STATE_REGISTERED_NONE
532
                )
533
            ) && !$linkedDocument;
534
        }
535
536
        return FALSE;
537
    }
538
539
    /**
540
     * @param \EWW\Dpf\Domain\Model\Document $document
541
     * @return bool
542
     */
543
    protected function canSuggestionAccept($document)
0 ignored issues
show
Unused Code introduced by
The parameter $document is not used and could be removed. ( Ignorable by Annotation )

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

543
    protected function canSuggestionAccept(/** @scrutinizer ignore-unused */ $document)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
544
    {
545
        // TODO: What if a document should be restored?
546
547
        return $this->librarianOnly();
548
    }
549
550
    /**
551
     * @param \EWW\Dpf\Domain\Model\Document $document
552
     * @return bool
553
     */
554
    protected function canPostpone($document)
555
    {
556
        if ($this->isDocumentLocked($document)) {
557
            return FALSE;
558
        }
559
560
        if ($this->workflow->can($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_POSTPONE)) {
561
            return $this->security->getUserRole() === Security::ROLE_LIBRARIAN;
562
        }
563
564
        return FALSE;
565
    }
566
567
568
    /**
569
     * @param \EWW\Dpf\Domain\Model\Document $document
570
     * @return bool
571
     */
572
    protected function canCreateAnonymously($document)
0 ignored issues
show
Unused Code introduced by
The parameter $document is not used and could be removed. ( Ignorable by Annotation )

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

572
    protected function canCreateAnonymously(/** @scrutinizer ignore-unused */ $document)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
573
    {
574
        if ($this->security->getUserRole()) {
575
            return FALSE;
576
        }
577
578
        return TRUE;
579
    }
580
581
    /**
582
     * @param \EWW\Dpf\Domain\Model\Document $document
583
     * @return bool
584
     */
585
    protected function canDuplicate($document)
586
    {
587
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
588
            return (
589
                $document->getState() !== DocumentWorkflow::STATE_NEW_NONE ||
590
                $document->getCreator() === $this->security->getUser()->getUid()
591
            );
592
        }
593
594
        if ($this->security->getUserRole() === Security::ROLE_RESEARCHER) {
595
            return (
596
                $document->getCreator() === $this->security->getUser()->getUid() ||
597
                $document->getState() !== DocumentWorkflow::STATE_NEW_NONE
598
            );
599
        }
600
601
        return FALSE;
602
    }
603
604
    /**
605
     * @param \EWW\Dpf\Domain\Model\Document $document
606
     * @return bool
607
     */
608
    protected function isDocumentLocked($document)
609
    {
610
        $identifier = $document->getObjectIdentifier()? $document->getObjectIdentifier() : $document->getUid();
611
        return $this->editingLockService->isLocked($identifier, $this->security->getUser()->getUid());
612
    }
613
614
    /**
615
     * @param \EWW\Dpf\Domain\Model\Document $document
616
     * @return bool
617
     */
618
    protected function canEditAnonymously($document)
619
    {
620
        if ($this->security->getUserRole()) {
621
            return FALSE;
622
        }
623
624
        return (
625
            $document->getCreator() === 0
626
            && $document->isTemporary()
627
            && $document->getState() === DocumentWorkflow::STATE_NEW_NONE
628
        );
629
630
        return FALSE;
0 ignored issues
show
Unused Code introduced by
return FALSE is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
631
    }
632
633
    /**
634
     * @param \EWW\Dpf\Domain\Model\Document $document
635
     * @return bool
636
     */
637
    protected function canRegisterAnonymously($document)
638
    {
639
        if ($this->security->getUserRole()) {
640
            return FALSE;
641
        }
642
643
        return (
644
            $this->workflow->can(
645
                $document, DocumentWorkflow::TRANSITION_REGISTER
646
            )
647
            && $document->getCreator() === 0
648
            && $document->isTemporary()
649
            && $document->getState() === DocumentWorkflow::STATE_NEW_NONE
650
        );
651
652
        return FALSE;
0 ignored issues
show
Unused Code introduced by
return FALSE is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
653
    }
654
655
}
656