Passed
Push — master ( 5189e1...6f3564 )
by Curtis
13:38 queued 10:53
created

GedcomExporter::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 46
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 29
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 46
rs 9.456
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Commands;
4
5
use Illuminate\Console\Command;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\Storage;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Storage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use FamilyTree365\LaravelGedcom\Models\Person;
8
use FamilyTree365\LaravelGedcom\Models\Subm;
9
use Illuminate\Support\Facades\DB;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\DB was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Illuminate\Support\Facades\View;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\View was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class GedcomExporter extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'gedcom:export {filename}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Export database data into a GEDCOM file format';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return mixed
42
     */
43
    public function handle()
44
    {
45
46
         $dir = 'public/gedcom/exported';
47
48
        $filename = $this->argument('filename').".GED";
49
50
        $file_path = $dir . '/' . $filename;
0 ignored issues
show
Unused Code introduced by
The assignment to $file_path is dead and can be removed.
Loading history...
51
52
        if (!file_exists($dir)) {
53
            Storage::makeDirectory($dir);
54
        }
55
56
        $query = DB::table('subms');
57
        $query->join('addrs', 'addrs.id', '=', 'subms.addr_id');
58
        $query->select([
59
            'subms.name',
60
            'addrs.adr1',
61
            'addrs.adr2',
62
            'addrs.city',
63
            'addrs.stae',
64
            'addrs.post',
65
            'addrs.ctry',
66
            'subms.phon',
67
        ])->get();
68
69
        $people = Person::all();
70
        $submissions = $query->get();
71
72
        $data =array (
73
            'submissions' => $submissions,
74
            'people' => $people,
75
        );
76
77
        $source = View::make('stubs.ged', $data)->render();
78
79
        $ged_doc = "HEAD \nGEDC \nVERS 5.5.5 \nFORM LINEAGE-LINKED \nVERS 5.5.5 \nCHAR UTF-8 \nSOUR GS \nVERS 5.5.5 \nCORP gedcom.org\n";
80
81
        $handle = fopen($filename, 'w');
82
83
        fputs($handle, $ged_doc.$source);
84
85
        fclose($handle);
86
87
        $headers = array(
0 ignored issues
show
Unused Code introduced by
The assignment to $headers is dead and can be removed.
Loading history...
88
            'Content-Type' => 'text/ged',
89
        );
90
91
    }
92
}
93