/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (CoverageRun::getActiveRun()) {
         $this->error('Error: Active runs exists');
         return;
     }
     $run = new CoverageRun();
     $run->name = 'Run';
     $run->active = true;
     $run->save();
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!($run = CoverageRun::getActiveRun())) {
         $this->error('No run found');
         return;
     }
     $run->active = false;
     $run->save();
 }
 public static function RecordEntry($category, $namespace, $name)
 {
     if (!Config::get('coverage.enabled')) {
         return;
     }
     $run = CoverageRun::getActiveRun();
     if (!$run) {
         \App::abort(404, 'Coverage Run not found');
     }
     $record = new self();
     $record->category = $category;
     $record->coverage_run_id = $run->id;
     $record->namespace = $namespace;
     $record->name = $name;
     $record->save();
     return $record;
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (CoverageRun::getActiveRun()) {
         $this->error('Error: Active runs exists. Stop run before running report');
         return;
     }
     $run = CoverageRun::orderBy('created_at', 'DESC')->first();
     if (!$run) {
         $this->error('No run found');
         return;
     }
     $runIds = [];
     array_push($runIds, $run->id);
     $actions = [];
     foreach ($this->routes as $route) {
         $actions[$route->getActionName()] = 0;
     }
     $records = CoverageRecord::whereIn('coverage_run_id', $runIds)->where('category', '=', 'Route')->get();
     foreach ($records as $record) {
         $actionName = $record->namespace . '@' . $record->name;
         $actions[$actionName] = 1;
     }
     $total = count($actions);
     $covered = 0;
     ksort($actions);
     $ignoreRoutes = config('coverage.ignore_routes');
     $ignoreRoutes = $ignoreRoutes ? $ignoreRoutes : [];
     foreach ($actions as $actionName => $count) {
         if (!$count) {
             if ($actionName == 'Closure') {
                 continue;
             }
             if (in_array($actionName, $ignoreRoutes)) {
                 continue;
             }
             list($namespace, $name) = explode('@', $actionName);
             if ($name == 'missingMethod') {
                 $method = new ReflectionMethod($namespace, $name);
                 $has = $method->class == $namespace;
                 if (!$has) {
                     continue;
                 }
             }
             $this->comment('Uncovered action ' . $actionName);
         } else {
             ++$covered;
         }
     }
     $this->comment("Route Coverage {$covered}/{$total}");
     $ignoreViews = config('coverage.ignore_views');
     $ignoreViews = $ignoreViews ? $ignoreViews : [];
     $views = [];
     foreach (\Config::get('view.paths') as $folder) {
         $finder = \Symfony\Component\Finder\Finder::create()->in($folder);
         foreach ($finder->files() as $i) {
             $views[$i->getRelativePathname()] = 0;
         }
     }
     foreach (view()->getFinder()->getHints() as $hint => $paths) {
         foreach ($paths as $path) {
             $finder = \Symfony\Component\Finder\Finder::create()->in($path);
             foreach ($finder->files() as $i) {
                 $path = $hint . '::' . $i->getRelativePathname();
                 $views[$path] = 0;
             }
         }
     }
     $records = CoverageRecord::whereIn('coverage_run_id', $runIds)->where('category', '=', 'View')->get();
     foreach ($records as $record) {
         $views[$record->name] = 1;
     }
     foreach ($ignoreViews as $key) {
         unset($views[$key]);
     }
     $total = count($views);
     $covered = 0;
     ksort($views);
     foreach ($views as $actionName => $count) {
         if (!$count) {
             $this->comment('Uncovered view ' . $actionName);
         } else {
             ++$covered;
         }
     }
     $this->comment("View Coverage {$covered}/{$total}");
 }