Skip to content

Commit c74788c

Browse files
committed
Fix coding style issues
1 parent ae9e214 commit c74788c

File tree

8 files changed

+611
-609
lines changed

8 files changed

+611
-609
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Laravel 5 NewRelic Service Provider
1+
# Laravel NewRelic Service Provider
22

33
| Laravel Version | Package Tag | Supported |
44
|-----------------|-------------|-----------|
5-
| 7.x.x | 3.0.x | yes |
6-
| 5.x.x | 2.2.x | yes |
7-
| 5.2.x | 2.1.x | yes |
8-
| 5.1.x | 2.0.x | yes |
9-
| 5.0.x | 2.0.x | no |
5+
| 9.x.x | 4.0.x | yes |
6+
| 8.x.x | 4.0.x | yes |
7+
| 7.x.x | 3.0.x | no |
8+
| 5.x.x | 2.2.x | no |
9+
| 5.2.x | 2.1.x | no |
10+
| 5.1.x | 2.0.x | no |
11+
| 5.0.x | 2.0.x | no |
1012

1113
*[see below for Laravel 4.x support](https://github.com/In-Touch/laravel-newrelic#laravel-4x-support)*
1214

@@ -52,7 +54,7 @@ other gathers their timings (in milliseconds). These recorded metrics will show
5254

5355
The `NewrelicCountingObserver` can be used for any observable model events, including your custom events. The
5456
`NewrelicTimingObserver` currently only supports the built-in Eloquent observable events (see
55-
[Model Events](https://laravel.com/docs/5.1/eloquent#events) in the Laravel documentation).
57+
[Model Events](https://laravel.com/docs/master/eloquent#events) in the Laravel documentation).
5658

5759
Using the observers is simple - wherever you choose to register your model observers, simply add:
5860

src/LaravelNewrelic/Facades/Newrelic.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
namespace Intouch\LaravelNewrelic\Facades;
1819

1920
use Illuminate\Support\Facades\Facade;
2021

22+
/**
23+
* @mixin \Intouch\Newrelic\Newrelic
24+
*/
2125
class Newrelic extends Facade
2226
{
2327
/**
@@ -29,5 +33,4 @@ protected static function getFacadeAccessor()
2933
{
3034
return 'newrelic';
3135
}
32-
33-
}
36+
}

src/LaravelNewrelic/LumenNewrelicMiddleware.php

Lines changed: 110 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2,118 +2,119 @@
22

33
namespace Intouch\LaravelNewrelic;
44

5-
use Illuminate\Http\Request as Request;
5+
use Illuminate\Http\Request;
66
use Closure;
77

88
class LumenNewrelicMiddleware
99
{
10-
/**
11-
* @param Request $request
12-
* @param Closure $next
13-
*/
14-
public function handle(Request $request, Closure $next)
15-
{
16-
$config = app()['config'];
17-
18-
if (true == $config->get('newrelic.auto_name_transactions')) {
19-
app('newrelic')->nameTransaction($this->getTransactionName());
20-
}
21-
$response = $next($request);
22-
23-
return $response;
24-
}
25-
26-
/**
27-
* Build the transaction name
28-
*
29-
* @return string
30-
*/
31-
public function getTransactionName()
32-
{
33-
return str_replace(
34-
[
35-
'{controller}',
36-
'{method}',
37-
'{route}',
38-
'{path}',
39-
'{uri}',
40-
],
41-
[
42-
$this->getController(),
43-
app('request')->getMethod(),
44-
$this->getRoute(),
45-
app('request')->getPathInfo(),
46-
app('request')->getUri(),
47-
],
48-
app('config')->get('newrelic.name_provider')
49-
);
50-
}
51-
52-
/**
53-
* Get the current route name, or controller if not named
54-
*
55-
* @return string
56-
*/
57-
protected function getRoute()
58-
{
59-
return $this->getRouteObject()['uri'];
60-
}
61-
62-
/**
63-
* Get the current controller / action
64-
*
65-
* @return string
66-
*/
67-
protected function getController()
68-
{
69-
return isset($this->getRouteObject()['action']['uses']) ? $this->getRouteObject()['action']['uses'] : 'Closure';
70-
}
71-
72-
/**
73-
* Get current route object
74-
* @date 2016-02-10
75-
* @return array
76-
*/
77-
protected function getRouteObject() {
78-
$request = app('request');
79-
80-
$verbs = 'GET|POST|PUT|DELETE|PATCH';
81-
82-
$routeToRegex = function ($string) use ($verbs) {
83-
$string = preg_replace("/^({$verbs})/", '', $string);
84-
$string = preg_replace('/\{\w+\}/', '[^/]+', $string);
85-
$string = preg_replace('/\{(\w+):(.+?)\}/', '\2', $string);
86-
return '#^'.$string.'$#';
87-
};
88-
89-
$routeToMethod = function ($string) use ($verbs) {
90-
return preg_replace("/^({$verbs}).+$/", '\1', $string);
91-
};
92-
93-
$routes = [];
94-
foreach (app()->getRoutes() as $routeName => $route) {
95-
$regex = $routeToRegex($routeName);
96-
$method = $routeToMethod($routeName);
97-
$routes[$method.$regex] = compact('route', 'method', 'regex');
98-
}
99-
100-
uksort($routes, function ($a, $b) {
101-
return strlen($b) - strlen($a);
102-
});
103-
104-
$method = $request->getMethod();
105-
$path = rtrim($request->getPathInfo(), '/');
106-
$foundRoute = null;
107-
108-
foreach ($routes as $regex => $details) {
109-
$regex = substr($regex, strlen($details['method']));
110-
if (true == preg_match($regex, $path) && $method == $details['method']) {
111-
$foundRoute = $details['route'];
112-
break;
113-
}
114-
}
115-
116-
return $foundRoute;
117-
}
10+
/**
11+
* @param Request $request
12+
* @param Closure $next
13+
*/
14+
public function handle(Request $request, Closure $next)
15+
{
16+
$config = app()['config'];
17+
18+
if (true == $config->get('newrelic.auto_name_transactions')) {
19+
app('newrelic')->nameTransaction($this->getTransactionName());
20+
}
21+
$response = $next($request);
22+
23+
return $response;
24+
}
25+
26+
/**
27+
* Build the transaction name
28+
*
29+
* @return string
30+
*/
31+
public function getTransactionName()
32+
{
33+
return str_replace(
34+
[
35+
'{controller}',
36+
'{method}',
37+
'{route}',
38+
'{path}',
39+
'{uri}',
40+
],
41+
[
42+
$this->getController(),
43+
app('request')->getMethod(),
44+
$this->getRoute(),
45+
app('request')->getPathInfo(),
46+
app('request')->getUri(),
47+
],
48+
app('config')->get('newrelic.name_provider')
49+
);
50+
}
51+
52+
/**
53+
* Get the current route name, or controller if not named
54+
*
55+
* @return string
56+
*/
57+
protected function getRoute()
58+
{
59+
return $this->getRouteObject()['uri'];
60+
}
61+
62+
/**
63+
* Get the current controller / action
64+
*
65+
* @return string
66+
*/
67+
protected function getController()
68+
{
69+
return isset($this->getRouteObject()['action']['uses']) ? $this->getRouteObject()['action']['uses'] : 'Closure';
70+
}
71+
72+
/**
73+
* Get current route object
74+
* @date 2016-02-10
75+
* @return array
76+
*/
77+
protected function getRouteObject()
78+
{
79+
$request = app('request');
80+
81+
$verbs = 'GET|POST|PUT|DELETE|PATCH';
82+
83+
$routeToRegex = function ($string) use ($verbs) {
84+
$string = preg_replace("/^({$verbs})/", '', $string);
85+
$string = preg_replace('/\{\w+\}/', '[^/]+', $string);
86+
$string = preg_replace('/\{(\w+):(.+?)\}/', '\2', $string);
87+
return '#^'.$string.'$#';
88+
};
89+
90+
$routeToMethod = function ($string) use ($verbs) {
91+
return preg_replace("/^({$verbs}).+$/", '\1', $string);
92+
};
93+
94+
$routes = [];
95+
foreach (app()->getRoutes() as $routeName => $route) {
96+
$regex = $routeToRegex($routeName);
97+
$method = $routeToMethod($routeName);
98+
$routes[$method.$regex] = compact('route', 'method', 'regex');
99+
}
100+
101+
uksort($routes, function ($a, $b) {
102+
return strlen($b) - strlen($a);
103+
});
104+
105+
$method = $request->getMethod();
106+
$path = rtrim($request->getPathInfo(), '/');
107+
$foundRoute = null;
108+
109+
foreach ($routes as $regex => $details) {
110+
$regex = substr($regex, strlen($details['method']));
111+
if (true == preg_match($regex, $path) && $method == $details['method']) {
112+
$foundRoute = $details['route'];
113+
break;
114+
}
115+
}
116+
117+
return $foundRoute;
118+
}
118119
}
119120

src/LaravelNewrelic/LumenNewrelicServiceProvider.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,41 @@
99

1010
class LumenNewrelicServiceProvider extends ServiceProvider
1111
{
12-
/**
13-
* Register the service provider.
14-
*
15-
* @return void
16-
*/
17-
public function register()
18-
{
19-
$this->app->configure('newrelic');
20-
$this->app->singleton(
21-
'newrelic',
22-
function ( $app ) {
23-
return new Newrelic( $app['config']->get( 'newrelic.throw_if_not_installed' ) );
24-
}
25-
);
12+
/**
13+
* Register the service provider.
14+
*
15+
* @return void
16+
*/
17+
public function register()
18+
{
19+
$this->app->configure('newrelic');
20+
$this->app->singleton(
21+
'newrelic',
22+
function ($app) {
23+
return new Newrelic($app['config']->get('newrelic.throw_if_not_installed'));
24+
}
25+
);
2626

27-
app('queue')->before(function (JobProcessing $event) {
28-
app('newrelic')->backgroundJob( true );
29-
app('newrelic')->startTransaction( ini_get('newrelic.appname') );
30-
if (app('config')->get( 'newrelic.auto_name_jobs' )) {
31-
app('newrelic')->nameTransaction( $this->getJobName($event) );
32-
}
33-
});
27+
app('queue')->before(function (JobProcessing $event) {
28+
app('newrelic')->backgroundJob(true);
29+
app('newrelic')->startTransaction(ini_get('newrelic.appname'));
30+
if (app('config')->get('newrelic.auto_name_jobs')) {
31+
app('newrelic')->nameTransaction($this->getJobName($event));
32+
}
33+
});
3434

35-
app('queue')->after(function (JobProcessed $event) {
36-
app('newrelic')->endTransaction();
37-
});
38-
}
35+
app('queue')->after(function (JobProcessed $event) {
36+
app('newrelic')->endTransaction();
37+
});
38+
}
3939

40-
/**
41-
* Build the job name
42-
*
43-
* @return string
44-
*/
45-
public function getJobName(JobProcessing $event)
46-
{
40+
/**
41+
* Build the job name
42+
*
43+
* @return string
44+
*/
45+
public function getJobName(JobProcessing $event)
46+
{
4747
return str_replace(
4848
[
4949
'{connection}',
@@ -53,7 +53,7 @@ public function getJobName(JobProcessing $event)
5353
$event->connectionName,
5454
$event->job->resolveName(),
5555
],
56-
$this->app['config']->get( 'newrelic.job_name_provider' )
56+
$this->app['config']->get('newrelic.job_name_provider')
5757
);
58-
}
58+
}
5959
}

0 commit comments

Comments
 (0)