public function testInspectThisRespository()
 {
     $settings = SettingsFactory::create();
     $inspector = new Inspector($settings);
     $repository = $inspector->getRepositoryByPath('.');
     static::assertInstanceOf(Repository::class, $repository);
     $results = $inspector->inspectRepository($repository);
     static::assertCount(26, $results['results']);
     static::assertTrue(in_array($results['remote'], ['https://github.com/swisnl/game-of-tests', 'https://github.com/swisnl/game-of-tests.git', 'git@github.com:swisnl/game-of-tests.git', 'git@github.com:swisnl/game-of-tests']), 'Check if remote is correct');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Getting directory list');
     // Bare respoitories
     $directory = rtrim(trim($this->argument('directory')), '/') . '/';
     $scanned_directory = array_diff(scandir($directory), array('..', '.'));
     $this->info('Found ' . count($scanned_directory) . ' directories');
     $progresbar = $this->output->createProgressBar(count($scanned_directory));
     $progresbar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message% ');
     $progresbar->setMessage('Searching...');
     \Swis\GotLaravel\Models\Results::unguard();
     $inspector = new Inspector($this->settings);
     foreach ($scanned_directory as $path) {
         $this->logVerbose('Inpecting: ' . $path);
         if (null !== $this->option('only') && strcmp($path, $this->option('only')) !== 0) {
             $progresbar->advance();
             continue;
         }
         if (null !== $this->option('skippast') && strcmp($path, $this->option('skippast')) <= 0) {
             $progresbar->advance();
             continue;
         }
         $repository = $inspector->getRepositoryByPath($directory . $path);
         // Check modified date
         if (null !== $this->option('modified')) {
             $modifiedTimestamp = strtotime($this->option('modified'));
             /**
              * @var $date \DateTime
              */
             try {
                 $this->logVerbose('Getting commit date');
                 $commitDate = $repository->getHeadCommit()->getCommitterDate();
             } catch (\Gitonomy\Git\Exception\ReferenceNotFoundException $e) {
                 $this->error($e->getMessage());
                 $this->error('Error finding reference for ' . $path);
             }
             if ($modifiedTimestamp === false || $commitDate->getTimestamp() < $modifiedTimestamp) {
                 $progresbar->advance();
                 continue;
             }
             $this->logVerbose('Don\'t skip');
         }
         $repository->setLogger(new ConsoleLogger($this->getOutput()));
         $this->logVerbose('Searching git');
         $resultSet = $inspector->inspectRepository($repository);
         $remote = $resultSet['remote'];
         $this->logVerbose('Found remote ' . $remote);
         if (count($resultSet['results']) > 0) {
             $progresbar->setMessage('Found ' . count($resultSet['results']) . ' tests for ' . $remote);
         }
         if (!$this->option('dry-run')) {
             foreach ($resultSet['results'] as $result) {
                 $insert = $result->toArray();
                 $insert['remote'] = $remote;
                 $insert['author_slug'] = Str::slug($result->getAuthor());
                 $insert['created_at'] = Carbon::createFromTimestamp($result->getDate());
                 try {
                     \Swis\GotLaravel\Models\Results::updateOrCreate(array_only($insert, ['remote', 'filename', 'line']), $insert);
                 } catch (\Exception $e) {
                     $this->error('Couldnt insert: ' . $e->getMessage() . PHP_EOL . print_r($insert, 1));
                 }
             }
         }
         $progresbar->advance();
     }
     Artisan::call('got:normalize-names');
 }