| Conditions | 3 |
| Paths | 3 |
| Total Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 69 | public function init() |
||
| 70 | { |
||
| 71 | parent::init(); |
||
| 72 | |||
| 73 | if ($this->src === null) { |
||
| 74 | throw new InvalidConfigException("The parameter src is required by the lazyload widget."); |
||
| 75 | } |
||
| 76 | |||
| 77 | // register the asset file |
||
| 78 | LazyLoadAsset::register($this->view); |
||
| 79 | |||
| 80 | // register js and css code with keys in order to ensure the registration is done only once |
||
| 81 | $this->view->registerJs("$('.lazy-image').lazyLoad();", View::POS_READY, self::JS_ASSET_KEY); |
||
| 82 | |||
| 83 | if ($this->placeholderSrc) { |
||
| 84 | $this->view->registerCss(" |
||
| 85 | .lazyimage-wrapper { |
||
| 86 | display: block; |
||
| 87 | width: 100%; |
||
| 88 | position: relative; |
||
| 89 | overflow: hidden; |
||
| 90 | } |
||
| 91 | .lazyimage { |
||
| 92 | position: absolute; |
||
| 93 | top: 50%; |
||
| 94 | left: 50%; |
||
| 95 | bottom: 0; |
||
| 96 | right: 0; |
||
| 97 | opacity: 0; |
||
| 98 | height: 100%; |
||
| 99 | width: 100%; |
||
| 100 | -webkit-transition: 1s ease-in-out opacity; |
||
| 101 | transition: 1s ease-in-out opacity; |
||
| 102 | -webkit-transform: translate(-50%,-50%); |
||
| 103 | transform: translate(-50%,-50%); |
||
| 104 | -o-object-fit: cover; |
||
| 105 | object-fit: cover; |
||
| 106 | -o-object-position: center center; |
||
| 107 | object-position: center center; |
||
| 108 | z-index: 20; |
||
| 109 | } |
||
| 110 | .lazyimage.loaded { |
||
| 111 | opacity: 1; |
||
| 112 | } |
||
| 113 | .lazyimage-placeholder-image { |
||
| 114 | display: block; |
||
| 115 | width: 100%; |
||
| 116 | height: auto; |
||
| 117 | } |
||
| 118 | .nojs .lazyimage, |
||
| 119 | .nojs .lazyimage-placeholder-image, |
||
| 120 | .no-js .lazyimage, |
||
| 121 | .no-js .lazyimage-placeholder-image { |
||
| 122 | display: none; |
||
| 123 | } |
||
| 124 | ", [], self::CSS_ASSET_KEY); |
||
| 125 | } else { |
||
| 126 | $this->view->registerCss(" |
||
| 127 | .lazy-image { |
||
| 128 | display: none; |
||
| 129 | } |
||
| 130 | .lazy-image.loaded { |
||
| 131 | display: block; |
||
| 132 | } |
||
| 133 | .lazy-placeholder { |
||
| 134 | background-color: #f2f2f2; |
||
| 135 | } |
||
| 136 | ", [], self::CSS_ASSET_KEY); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 169 |