Skip to content

Commit 0fed77b

Browse files
committed
remove ref to env and use config
1 parent be0ec62 commit 0fed77b

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

config/eloquentize.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
// config for Eloquentize/LaravelClient
44
return [
55
'api_url' => env('ELOQUENTIZE_API_URL', 'https://eloquentize.com'),
6+
'ELOQUENTIZE_API_TOKEN' => env('ELOQUENTIZE_API_TOKEN', 'Please define ELOQUENTIZE_API_TOKEN in your .env file'),
67
];

src/Commands/BaseCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ class BaseCommand extends Command
1414

1515
protected function execute(InputInterface $input, OutputInterface $output): int
1616
{
17-
if (env('ELOQUENTIZE_API_TOKEN') === null) {
17+
if (config('eloquentize.ELOQUENTIZE_API_TOKEN') === null) {
1818
throw new \Exception('ELOQUENTIZE_API_TOKEN is not set in .env');
1919
}
2020

21-
if (env('APP_URL') === null) {
21+
if (config('app.url') === null) {
2222
throw new \Exception('app.url is not set in .env');
2323
}
24-
if (env('APP_ENV') === null) {
24+
if (config('app.env') === null) {
2525
throw new \Exception('app.env is not set in .env');
2626
}
27-
if (env('APP_URL') === 'http://localhost') {
27+
if (config('app.url') === 'http://localhost') {
2828
throw new \Exception('app.url is set to http://localhost. Please change these values in .env bevause eloquentize identifies the environment by the app.url and app.env values.');
2929
}
3030

src/Commands/ModelCountOverall.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Eloquentize\LaravelClient\Commands;
44

55
use Carbon\CarbonPeriod;
6-
use Illuminate\Support\Carbon;
7-
use Eloquentize\LaravelClient\Commands\Traits\HasVerbose;
86
use Eloquentize\LaravelClient\Commands\Traits\BuildPeriod;
97
use Eloquentize\LaravelClient\Commands\Traits\DateArgument;
108
use Eloquentize\LaravelClient\Commands\Traits\GatherModels;
9+
use Eloquentize\LaravelClient\Commands\Traits\HasVerbose;
1110
use Eloquentize\LaravelClient\Commands\Traits\ModelsOption;
12-
use Eloquentize\LaravelClient\Commands\Traits\SendMetricsData;
1311
use Eloquentize\LaravelClient\Commands\Traits\PrepareMetricsData;
12+
use Eloquentize\LaravelClient\Commands\Traits\SendMetricsData;
13+
use Illuminate\Support\Carbon;
1414

1515
class ModelCountOverall extends BaseCommand
1616
{
@@ -29,7 +29,6 @@ public function perform(string $model, $modelsPath = null, ?string $scope = null
2929
$metrics = [];
3030
$modelClass = $this->getModelClass($model, $modelsPath);
3131

32-
3332
try {
3433

3534
// sound avg / min / max / sum return 0 if no records found ? for now
@@ -86,7 +85,7 @@ public function handle()
8685
$period = new CarbonPeriod($oldestDate, Carbon::now()->endOfDay());
8786
$metricsData = $this->prepareMetricsData($metrics, $period, 'overall');
8887

89-
$this->sendMetricsData($metricsData, env('ELOQUENTIZE_API_TOKEN'));
88+
$this->sendMetricsData($metricsData, config('eloquentize.ELOQUENTIZE_API_TOKEN'));
9089

9190
return 0;
9291
}

src/Commands/ModelsCount.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function handle()
107107
$this->line('');
108108
$this->line('----- Source data -----');
109109
$this->line('The data will be stored in source :');
110-
$this->info('***** '.$this->cleanAppUrl(env('APP_URL')).'-'.env('APP_ENV').' *****');
110+
$this->info('***** '.$this->cleanAppUrl(config('app.url')).'-'.config('app.env').' *****');
111111
$this->line('Be sure to define a relevant source name by setting APP_URL ');
112112
$this->line('');
113113
$this->line('----- Models tracked -----');
@@ -119,7 +119,7 @@ public function handle()
119119

120120
return 0;
121121
} else {
122-
$this->sendMetricsData($metricsData, env('ELOQUENTIZE_API_TOKEN'));
122+
$this->sendMetricsData($metricsData, config('eloquentize.ELOQUENTIZE_API_TOKEN'));
123123
}
124124

125125
$this->line('Models count data sent to eloquentize.');

src/Commands/PropertyAggregate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function handle()
102102
$metrics = $this->perform($model, $aggregation, $property, $period, $event, $modelsPath, $scope, $scopeValue);
103103
$metricsData = $this->prepareMetricsData($metrics, $period, $event);
104104

105-
$this->sendMetricsData($metricsData, env('ELOQUENTIZE_API_TOKEN'));
105+
$this->sendMetricsData($metricsData, config('eloquentize.ELOQUENTIZE_API_TOKEN'));
106106

107107
return 0;
108108

src/Commands/PropertyAggregateOverall.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function perform(string $model, AggregationType $aggregation, string $pro
5252
$count = $query->$method($property) ?? 0;
5353
$this->verbose('The '.$method.' of '.$model.'->'.$property.' overall is : '.$count);
5454

55-
$label = 'Overall ' .$model;
55+
$label = 'Overall '.$model;
5656
if ($scope && $scopeValue) {
5757
$label .= '::'.$scope.'('.$scopeValue.')';
5858
} elseif ($scope) {
@@ -92,7 +92,7 @@ public function handle()
9292
$period = new CarbonPeriod($oldestDate, Carbon::now()->endOfDay());
9393
$metricsData = $this->prepareMetricsData($metrics, $period, 'overall');
9494

95-
$this->sendMetricsData($metricsData, env('ELOQUENTIZE_API_TOKEN'));
95+
$this->sendMetricsData($metricsData, config('eloquentize.ELOQUENTIZE_API_TOKEN'));
9696

9797
return 0;
9898

src/Commands/Traits/SendMetricsData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function sendMetricsData($data, $token)
1313
$response = Http::acceptJson()->withToken($token)->post($url, $data);
1414

1515
if ($response->successful()) {
16-
$this->info('Data successfully sent to Eloquentize');
16+
$this->info('Data successfully sent to Eloquentize!');
1717
} else {
1818
$this->error('Data sending failed', 'error');
1919
$this->error($response->body(), 'error');

src/LaravelClientServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Eloquentize\LaravelClient;
44

5-
use Spatie\LaravelPackageTools\Package;
6-
use Eloquentize\LaravelClient\Commands\ModelsCount;
7-
use Spatie\LaravelPackageTools\PackageServiceProvider;
85
use Eloquentize\LaravelClient\Commands\ModelCountOverall;
6+
use Eloquentize\LaravelClient\Commands\ModelsCount;
97
use Eloquentize\LaravelClient\Commands\ModelsCountLegacy;
108
use Eloquentize\LaravelClient\Commands\PropertyAggregate;
119
use Eloquentize\LaravelClient\Commands\PropertyAggregateLegacy;
1210
use Eloquentize\LaravelClient\Commands\PropertyAggregateOverall;
11+
use Spatie\LaravelPackageTools\Package;
12+
use Spatie\LaravelPackageTools\PackageServiceProvider;
1313

1414
class LaravelClientServiceProvider extends PackageServiceProvider
1515
{

tests/commands/BuildPeriodTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
it('ensure BuildPeriod trait create a CarbonPeriod instance', function () {
77

8-
$periodBuilder = new PeriodBuilder();
8+
$periodBuilder = new PeriodBuilder;
99

1010
$date = '2021-01-01 00:00:00';
1111
$periodType = 'daily';

0 commit comments

Comments
 (0)