Skip to content

Commit 7d075e2

Browse files
Merge remote-tracking branch 'origin/master' into master
2 parents 676b9bd + 07799a7 commit 7d075e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1111
-1198
lines changed

src/Commands/GedcomImporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace ModularSoftware\LaravelGedcom\Commands;
44

5-
use ModularSoftware\LaravelGedcom\Facades\GedcomParserFacade;
65
use Illuminate\Console\Command;
6+
use ModularSoftware\LaravelGedcom\Facades\GedcomParserFacade;
77

88
class GedcomImporter extends Command
99
{

src/Facades/GedcomParserFacade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ protected static function getFacadeAccessor()
1010
{
1111
return 'modularsoftware/laravel-gedcom:parser';
1212
}
13-
}
13+
}

src/Observers/EventActionsObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ public function saving($model)
1111
$parser = new DateParser($model->date);
1212
$model->fill($parser->parse_date());
1313
}
14-
}
14+
}

src/ServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
1010
public function register()
1111
{
1212
$this->commands([
13-
GedcomImporter::class
13+
GedcomImporter::class,
1414
]);
1515

1616
$this->app->bind('modularsoftware/laravel-gedcom:parser', function () {
@@ -20,6 +20,6 @@ public function register()
2020

2121
public function boot()
2222
{
23-
$this->loadMigrationsFrom(__DIR__ . '/migrations/');
23+
$this->loadMigrationsFrom(__DIR__.'/migrations/');
2424
}
25-
}
25+
}

src/Utils/DateParser.php

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22

33
namespace ModularSoftware\LaravelGedcom\Utils;
44

5-
class DateParser {
6-
5+
class DateParser
6+
{
77
private $date_string;
8-
private $year = NULL;
9-
private $month = NULL;
10-
private $day =NULL;
8+
private $year = null;
9+
private $month = null;
10+
private $day = null;
1111

12-
public function __construct($date_string = "")
12+
public function __construct($date_string = '')
1313
{
1414
$this->date_string = $date_string;
1515
}
1616

1717
public function parse_date()
1818
{
1919
$this->trim_datestring();
20-
if(!$this->try_parse_full_date()){
21-
if(!$this->try_parse_M_Y_date()){
22-
if(!$this->try_parse_Y_date()){
20+
if (!$this->try_parse_full_date()) {
21+
if (!$this->try_parse_M_Y_date()) {
22+
if (!$this->try_parse_Y_date()) {
2323
$this->set_null_date();
2424
}
2525
}
2626
}
27+
2728
return $this->export();
2829
}
2930

@@ -37,86 +38,91 @@ private function trim_datestring()
3738
// Takes a property over a certain period of time ( e.g. exercise of a profession, living in a particular place )
3839
'FROM', 'TO',
3940
];
40-
foreach($words_to_remove as $word){
41-
$this->date_string = str_replace($word, "" , $this->date_string);
42-
};
41+
foreach ($words_to_remove as $word) {
42+
$this->date_string = str_replace($word, '', $this->date_string);
43+
}
4344
$this->date_string = trim($this->date_string);
4445
}
4546

46-
private function try_parse_full_date ()
47+
private function try_parse_full_date()
4748
{
4849
$this->set_null_date(); // Default
49-
$date_parts = explode(" ", $this->date_string);
50-
if(count($date_parts)>3){
50+
$date_parts = explode(' ', $this->date_string);
51+
if (count($date_parts) > 3) {
5152
return false;
5253
}
54+
5355
return $this->try_get_day(
54-
$date_parts[0]?? false
55-
)
56+
$date_parts[0] ?? false
57+
)
5658
and
5759
$this->try_get_month(
58-
$date_parts[1]?? false
60+
$date_parts[1] ?? false
5961
)
6062
and
6163
$this->try_get_year(
62-
$date_parts[2]?? false,
63-
$date_parts[3]?? false
64+
$date_parts[2] ?? false,
65+
$date_parts[3] ?? false
6466
);
6567
}
6668

67-
private function try_parse_M_Y_date ()
69+
private function try_parse_M_Y_date()
6870
{
6971
$this->set_null_date(); // Default
70-
$date_parts = explode(" ", $this->date_string);
71-
if(count($date_parts)>3){
72+
$date_parts = explode(' ', $this->date_string);
73+
if (count($date_parts) > 3) {
7274
return false;
7375
}
76+
7477
return $this->try_get_month(
75-
$date_parts[0]?? false
76-
)
78+
$date_parts[0] ?? false
79+
)
7780
and
7881
$this->try_get_year(
79-
$date_parts[1]?? false,
80-
$date_parts[2]?? false
82+
$date_parts[1] ?? false,
83+
$date_parts[2] ?? false
8184
);
8285
}
83-
private function try_parse_Y_date ()
86+
87+
private function try_parse_Y_date()
8488
{
8589
$this->set_null_date(); // Default
86-
$date_parts = explode(" ", $this->date_string);
87-
if(count($date_parts)>2){
90+
$date_parts = explode(' ', $this->date_string);
91+
if (count($date_parts) > 2) {
8892
return false;
8993
}
94+
9095
return $this->try_get_year(
91-
$date_parts[0]?? false,
92-
$date_parts[1]?? false
96+
$date_parts[0] ?? false,
97+
$date_parts[1] ?? false
9398
);
9499
}
95-
private function try_get_year ($year, $epoch=false)
100+
101+
private function try_get_year($year, $epoch = false)
96102
{
97103
$sign = 1;
98-
if($epoch){
99-
if($epoch=='BC'){
104+
if ($epoch) {
105+
if ($epoch == 'BC') {
100106
$sign = -1;
101-
}else if($epoch=='AC'){
107+
} elseif ($epoch == 'AC') {
102108
$sign = 1;
103-
}else{
109+
} else {
104110
return false;
105111
}
106112
}
107-
if(!$year){
113+
if (!$year) {
108114
return false;
109115
}
110-
if(is_numeric($year)){
116+
if (is_numeric($year)) {
111117
$this->year = $year * $sign;
112-
}else{
118+
} else {
113119
return false;
114120
}
115121

116122
return true;
117123
}
118124

119-
private function try_get_month ($month)
125+
private function try_get_month($month)
120126
{
121127
$months = [
122128
'JAN' => 1,
@@ -133,31 +139,31 @@ private function try_get_month ($month)
133139
'DEC' => 12,
134140
];
135141

136-
if(isset($months[$month])){
142+
if (isset($months[$month])) {
137143
$this->month = $months[$month];
144+
138145
return true;
139-
}else{
146+
} else {
140147
return false;
141148
}
142-
143149
}
144150

145-
private function try_get_day ($day)
151+
private function try_get_day($day)
146152
{
147-
if(is_numeric($day)){
148-
$this->day = $day*1;
153+
if (is_numeric($day)) {
154+
$this->day = $day * 1;
155+
149156
return true;
150-
}else{
157+
} else {
151158
return false;
152159
}
153-
154160
}
155161

156162
public function set_null_date()
157163
{
158-
$this->year = NULL;
159-
$this->month = NULL;
160-
$this->day = NULL;
164+
$this->year = null;
165+
$this->month = null;
166+
$this->day = null;
161167
}
162168

163169
public function export()
@@ -168,4 +174,4 @@ public function export()
168174
'day' => $this->day,
169175
];
170176
}
171-
}
177+
}

0 commit comments

Comments
 (0)