| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function generate($id = null) |
||
| 20 | { |
||
| 21 | if(is_null($id)) { |
||
| 22 | throw new AutopromoBannerIdMissing(); |
||
| 23 | } |
||
| 24 | |||
| 25 | if (!$this->cache->isAutopromoBannerConfigured()) { |
||
| 26 | return ''; |
||
| 27 | } |
||
| 28 | |||
| 29 | $url = $this->cache->getAutopromoBannerUrl(); |
||
| 30 | $script = $this->cache->getAutopromoBannerScript(); |
||
| 31 | |||
| 32 | $script = <<<EOS |
||
| 33 | (function (a,d){var s,t,cs,ds,dd;s=d.createElement('script');cs=d.currentScript; |
||
| 34 | ds=d.createElement('span');ds.id=Math.random().toString(36).substring(7); |
||
| 35 | dd=cs.parentNode.insertBefore(ds,cs); |
||
| 36 | s.src=a;s.async=1;s.setAttribute('data-dd',ds.id);s.setAttribute('data-id',$id); |
||
| 37 | t=d.getElementsByTagName('script')[0];t.parentNode.insertBefore(s,t);}) |
||
| 38 | ("https://$url/$script.js", document); |
||
| 39 | EOS; |
||
| 40 | |||
| 41 | return $script; |
||
| 42 | } |
||
| 43 | } |
||
| 44 |