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