Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit 59fa1f3

Browse files
author
rok
committed
polished source code with editorconfig of laravel itself
using facade classes instead of facade aliases removed laravel 4 support entirely
1 parent 339534b commit 59fa1f3

10 files changed

+205
-169
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

src/Ipunkt/LaravelAnalytics/AnalyticsFacade.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Ipunkt\LaravelAnalytics;
44

55
use Illuminate\Support\Facades\Facade;
6+
use Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface;
67

78
/**
89
* Class AnalyticsFacade
@@ -18,6 +19,6 @@ class AnalyticsFacade extends Facade
1819
*/
1920
protected static function getFacadeAccessor()
2021
{
21-
return 'Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface';
22+
return AnalyticsProviderInterface::class;
2223
}
2324
}

src/Ipunkt/LaravelAnalytics/AnalyticsServiceProvider.php

+25-44
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Ipunkt\LaravelAnalytics;
44

5-
use Config;
5+
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\ServiceProvider;
77

88
class AnalyticsServiceProvider extends ServiceProvider
@@ -21,12 +21,6 @@ class AnalyticsServiceProvider extends ServiceProvider
2121
*/
2222
public function boot()
2323
{
24-
if ($this->isLaravel4()) {
25-
$this->package('ipunkt/laravel-analytics');
26-
27-
return;
28-
}
29-
3024
$config = realpath(__DIR__ . '/../../config/analytics.php');
3125

3226
$this->mergeConfigFrom($config, 'analytics');
@@ -43,33 +37,30 @@ public function boot()
4337
*/
4438
public function register()
4539
{
46-
$packageNamespace = $this->isLaravel4() ? 'laravel-analytics::' : '';
47-
48-
$this->app->singleton('Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface', function () use ($packageNamespace) {
49-
50-
// get analytics provider name
51-
$provider = Config::get($packageNamespace . 'analytics.provider');
52-
53-
// make it a class
54-
$providerClass = 'Ipunkt\LaravelAnalytics\Providers\\' . $provider;
55-
56-
// getting the config
57-
$providerConfig = [];
58-
if (Config::has($packageNamespace . 'analytics.configurations.' . $provider)) {
59-
$providerConfig = Config::get($packageNamespace . 'analytics.configurations.' . $provider);
60-
}
61-
62-
// make provider instance
63-
$instance = new $providerClass($providerConfig);
64-
65-
// check if we want to prematurely disable the script block
66-
if (Config::get($packageNamespace . 'analytics.disable_script_block', false)) {
67-
$instance->disableScriptBlock();
68-
}
69-
70-
// return the provider instance
71-
return $instance;
72-
});
40+
$this->app->singleton('Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface',
41+
function () {
42+
// get analytics provider name
43+
$provider = Config::get('analytics.provider');
44+
45+
// make it a class
46+
$providerClass = 'Ipunkt\LaravelAnalytics\Providers\\' . $provider;
47+
48+
// getting the config
49+
$providerConfig = [];
50+
if (Config::has('analytics.configurations.' . $provider)) {
51+
$providerConfig = Config::get('analytics.configurations.' . $provider);
52+
}
53+
54+
// make provider instance
55+
$instance = new $providerClass($providerConfig);
56+
57+
// check if we want to prematurely disable the script block
58+
if (Config::get('analytics.disable_script_block', false)) {
59+
$instance->disableScriptBlock();
60+
}
61+
62+
return $instance;
63+
});
7364
}
7465

7566
/**
@@ -81,14 +72,4 @@ public function provides()
8172
{
8273
return [];
8374
}
84-
85-
/**
86-
* are we on laravel 4
87-
*
88-
* @return bool
89-
*/
90-
private function isLaravel4()
91-
{
92-
return version_compare(\Illuminate\Foundation\Application::VERSION, '5', '<');
93-
}
9475
}

src/Ipunkt/LaravelAnalytics/Contracts/AnalyticsProviderInterface.php

+27-11
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public function disableAutoTracking();
8282
/**
8383
* render script block
8484
*
85-
* @return $this
85+
* @return AnalyticsProviderInterface
8686
*/
8787
public function enableScriptBlock();
8888

8989
/**
9090
* do not render script block
9191
*
92-
* @return $this
92+
* @return AnalyticsProviderInterface
9393
*/
9494
public function disableScriptBlock();
9595

@@ -150,6 +150,7 @@ public function unsetUserId();
150150
* sets a campaign
151151
*
152152
* @param Campaign $campaign
153+
*
153154
* @return AnalyticsProviderInterface
154155
*/
155156
public function setCampaign(Campaign $campaign);
@@ -187,7 +188,14 @@ public function disableEcommerceTracking();
187188
*
188189
* @return AnalyticsProviderInterface
189190
*/
190-
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null, $currency = null);
191+
public function ecommerceAddTransaction(
192+
$id,
193+
$affiliation = null,
194+
$revenue = null,
195+
$shipping = null,
196+
$tax = null,
197+
$currency = null
198+
);
191199

192200
/**
193201
* ecommerce tracking - add item
@@ -202,7 +210,15 @@ public function ecommerceAddTransaction($id, $affiliation = null, $revenue = nul
202210
*
203211
* @return AnalyticsProviderInterface
204212
*/
205-
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null, $currency = null);
213+
public function ecommerceAddItem(
214+
$id,
215+
$name,
216+
$sku = null,
217+
$category = null,
218+
$price = null,
219+
$quantity = null,
220+
$currency = null
221+
);
206222

207223
/**
208224
* sets custom dimensions
@@ -213,13 +229,13 @@ public function ecommerceAddItem($id, $name, $sku = null, $category = null, $pri
213229
*/
214230
public function setCustom($dimension, $value = null);
215231

216-
/**
217-
* set a custom tracking ID (the UA-XXXXXXXX-1 code)
218-
*
219-
* @param string $trackingId
220-
*
221-
* @return AnalyticsProviderInterface
222-
*/
232+
/**
233+
* set a custom tracking ID (the UA-XXXXXXXX-1 code)
234+
*
235+
* @param string $trackingId
236+
*
237+
* @return AnalyticsProviderInterface
238+
*/
223239
public function setTrackingId($trackingId);
224240

225241
/**

src/Ipunkt/LaravelAnalytics/Data/Campaign.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public function getKeyword()
139139
* sets keyword
140140
*
141141
* @param string $keyword
142-
* @return $this
142+
*
143+
* @return \Ipunkt\LaravelAnalytics\Data\Campaign
143144
*/
144145
public function setKeyword($keyword)
145146
{
@@ -161,7 +162,8 @@ public function getContent()
161162
* sets content
162163
*
163164
* @param string $content
164-
* @return $this
165+
*
166+
* @return \Ipunkt\LaravelAnalytics\Data\Campaign
165167
*/
166168
public function setContent($content)
167169
{
@@ -183,7 +185,8 @@ public function getId()
183185
* sets id
184186
*
185187
* @param string $id
186-
* @return $this
188+
*
189+
* @return \Ipunkt\LaravelAnalytics\Data\Campaign
187190
*/
188191
public function setId($id)
189192
{

src/Ipunkt/LaravelAnalytics/Data/Renderer/CampaignRenderer.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function __construct(Campaign $campaign)
3030
public function render()
3131
{
3232
return $this->renderName()
33-
. $this->renderSource()
34-
. $this->renderMedium()
35-
. $this->renderKeyword()
36-
. $this->renderContent()
37-
. $this->renderId();
33+
. $this->renderSource()
34+
. $this->renderMedium()
35+
. $this->renderKeyword()
36+
. $this->renderContent()
37+
. $this->renderId();
3838
}
3939

4040
/**
@@ -45,6 +45,7 @@ public function render()
4545
private function renderName()
4646
{
4747
$name = $this->campaign->getName();
48+
4849
return empty($name) ? '' : "ga('set', 'campaignName', '{$name}');";
4950
}
5051

@@ -56,6 +57,7 @@ private function renderName()
5657
private function renderSource()
5758
{
5859
$source = $this->campaign->getSource();
60+
5961
return empty($source) ? '' : "ga('set', 'campaignSource', '{$source}');";
6062
}
6163

@@ -67,6 +69,7 @@ private function renderSource()
6769
private function renderMedium()
6870
{
6971
$medium = $this->campaign->getMedium();
72+
7073
return empty($medium) ? '' : "ga('set', 'campaignMedium', '{$medium}');";
7174
}
7275

@@ -78,6 +81,7 @@ private function renderMedium()
7881
private function renderKeyword()
7982
{
8083
$keyword = $this->campaign->getKeyword();
84+
8185
return empty($keyword) ? '' : "ga('set', 'campaignKeyword', '{$keyword}');";
8286
}
8387

@@ -89,6 +93,7 @@ private function renderKeyword()
8993
private function renderContent()
9094
{
9195
$content = $this->campaign->getContent();
96+
9297
return empty($content) ? '' : "ga('set', 'campaignContent', '{$content}');";
9398
}
9499

@@ -100,6 +105,7 @@ private function renderContent()
100105
private function renderId()
101106
{
102107
$id = $this->campaign->getId();
108+
103109
return empty($id) ? '' : "ga('set', 'campaignId', '{$id}');";
104110
}
105111
}

0 commit comments

Comments
 (0)