Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

burzum / cakephp-user-tools / 318

7 Sep 2017 - 14:12 coverage: 37.811% (-0.6%) from 38.365%
318

Pull #46

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Improving the code and doc blocks
Pull Request #46: Updating the plugin to CakePHP 3.4 changes

43 of 114 new or added lines in 7 files covered. (37.72%)

21 existing lines in 4 files now uncovered.

304 of 804 relevant lines covered (37.81%)

2.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0
/src/Controller/Component/FlashAndRedirectTrait.php
1
<?php
2
/**
3
 * FlashAndRedirectTrait
4
 *
5
 * @author Florian Krämer
6
 * @copyright 2013 - 2017 Florian Krämer
7
 * @license MIT
8
 */
9
namespace Burzum\UserTools\Controller\Component;
10

11
/**
12
 * FlashAndRedirectTrait
13
 *
14
 * @property \Cake\Controller\ComponentRegistry $_registry
15
 */
16
trait FlashAndRedirectTrait {
17

18
        /**
19
         * Helper property to detect a redirect
20
         *
21
         * @see UserToolComponent::handleFlashAndRedirect();
22
         * @var \Cake\Http\Response|null
23
         */
24
        protected $_redirectResponse = null;
25

26
        /**
27
         * Handles flashes and redirects
28
         *
29
         * @param string $type Prefix for the array key, mostly "success" or "error"
30
         * @param array $options Options
31
         * @return mixed
32
         */
33
        public function handleFlashAndRedirect($type, $options) {
34
                $this->_handleFlash($type, $options);
!
35

UNCOV
36
                return $this->_handleRedirect($type, $options);
!
37
        }
38

39
        /**
40
         * Handles the redirect options.
41
         *
42
         * @param string $type Prefix for the array key, mostly "success" or "error"
43
         * @param array $options Options
44
         * @return mixed
45
         */
46
        protected function _handleRedirect($type, $options) {
47
                if (isset($options[$type . 'RedirectUrl']) && $options[$type . 'RedirectUrl'] !== false) {
!
NEW
48
                        $controller = $this->getController();
!
49
                        $result = $controller->redirect($options[$type . 'RedirectUrl']);
!
50
                        $this->_redirectResponse = $result;
!
51

UNCOV
52
                        return $result;
!
53
                }
54

55
                $this->_redirectResponse = null;
!
56

57
                return false;
!
58
        }
59

60
        /**
61
         * Handles the flash options.
62
         *
63
         * @param string $type Prefix for the array key, mostly "success" or "error"
64
         * @param array $options Options
65
         * @return bool
66
         */
67
        protected function _handleFlash($type, $options) {
68
                if (isset($options[$type . 'Message']) && $options[$type . 'Message'] !== false) {
!
69
                        if (is_string($options[$type . 'Message'])) {
!
70
                                $flashOptions = [];
!
71
                                if (isset($options[$type . 'FlashOptions'])) {
!
72
                                        $flashOptions = $options[$type . 'FlashOptions'];
!
73
                                }
74

75
                                if (!isset($flashOptions['element'])) {
!
NEW
76
                                        if (!$this->_registry->has('Flash')) {
!
NEW
77
                                                $this->_registry->load('Flash');
!
78
                                        }
79

80
                                        $flashOptions['element'] = $type;
!
NEW
81
                                        $this->_registry->get('Flash')->set($options[$type . 'Message'], $flashOptions);
!
82
                                }
83

84
                                return true;
!
85
                        }
86
                }
87

88
                return false;
!
89
        }
90
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc