@@ -46,15 +46,14 @@ public function __construct()
46
46
public function handle ()
47
47
{
48
48
$ experiments = Experiment::active ()->get ();
49
- $ goals = array_unique (Goal::active ()->orderBy ('name ' )->lists ('name ' ));
49
+ $ goals = array_unique (Goal::active ()->orderBy ('name ' )->pluck ('name ' )-> toArray ( ));
50
50
51
51
$ columns = array_merge (['Experiment ' , 'Visitors ' , 'Engagement ' ], array_map ('ucfirst ' , $ goals ));
52
52
53
53
$ writer = new Writer (new SplTempFileObject );
54
54
$ writer ->insertOne ($ columns );
55
55
56
- foreach ($ experiments as $ experiment )
57
- {
56
+ foreach ($ experiments as $ experiment ) {
58
57
$ engagement = $ experiment ->visitors ? ($ experiment ->engagement / $ experiment ->visitors * 100 ) : 0 ;
59
58
60
59
$ row = [
@@ -63,10 +62,9 @@ public function handle()
63
62
number_format ($ engagement , 2 ) . " % ( " . $ experiment ->engagement .") " ,
64
63
];
65
64
66
- $ results = $ experiment ->goals ()->lists ('count ' , 'name ' );
65
+ $ results = $ experiment ->goals ()->pluck ('count ' , 'name ' );
67
66
68
- foreach ($ goals as $ column )
69
- {
67
+ foreach ($ goals as $ column ) {
70
68
$ count = array_get ($ results , $ column , 0 );
71
69
$ percentage = $ experiment ->visitors ? ($ count / $ experiment ->visitors * 100 ) : 0 ;
72
70
@@ -78,13 +76,11 @@ public function handle()
78
76
79
77
$ output = (string ) $ writer ;
80
78
81
- if ($ file = $ this ->argument ('file ' ))
82
- {
79
+ if ($ file = $ this ->argument ('file ' )) {
83
80
$ this ->info ("Creating $ file " );
84
81
85
82
File::put ($ file , $ output );
86
- }
87
- else
83
+ } else
88
84
{
89
85
$ this ->line ($ output );
90
86
}
0 commit comments