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