Skip to content

Commit dfaf4c9

Browse files
committed
Remove duplicate code
1 parent 0454e48 commit dfaf4c9

10 files changed

Lines changed: 217 additions & 332 deletions

File tree

src/Helper/Diff.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/Model/Base/Build.php

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PHPCensor\Common\Exception\InvalidArgumentException;
1010
use PHPCensor\Model;
1111
use PHPCensor\Store\BuildStore;
12+
use PHPCensor\Traits\Model\HasCreateDateTrait;
13+
use PHPCensor\Traits\Model\HasUserIdTrait;
1214

1315
/**
1416
* @package PHP Censor
@@ -19,6 +21,9 @@
1921
*/
2022
class Build extends Model
2123
{
24+
use HasUserIdTrait;
25+
use HasCreateDateTrait;
26+
2227
public const STATUS_PENDING = 0;
2328
public const STATUS_RUNNING = 1;
2429
public const STATUS_SUCCESS = 2;
@@ -300,36 +305,6 @@ public function setTag(?string $value)
300305
return $this->setModified('tag');
301306
}
302307

303-
/**
304-
* @return DateTime|null
305-
*
306-
* @throws Exception
307-
*/
308-
public function getCreateDate()
309-
{
310-
if ($this->data['create_date']) {
311-
return new DateTime($this->data['create_date']);
312-
}
313-
314-
return null;
315-
}
316-
317-
/**
318-
* @return bool
319-
*/
320-
public function setCreateDate(DateTime $value)
321-
{
322-
$stringValue = $value->format('Y-m-d H:i:s');
323-
324-
if ($this->data['create_date'] === $stringValue) {
325-
return false;
326-
}
327-
328-
$this->data['create_date'] = $stringValue;
329-
330-
return $this->setModified('create_date');
331-
}
332-
333308
/**
334309
* @return DateTime|null
335310
*
@@ -521,28 +496,6 @@ public function setSource(?int $value)
521496
return $this->setModified('source');
522497
}
523498

524-
/**
525-
* @return int|null
526-
*/
527-
public function getUserId()
528-
{
529-
return (null !== $this->data['user_id']) ? (int)$this->data['user_id'] : null;
530-
}
531-
532-
/**
533-
* @return bool
534-
*/
535-
public function setUserId(?int $value)
536-
{
537-
if ($this->data['user_id'] === $value) {
538-
return false;
539-
}
540-
541-
$this->data['user_id'] = $value;
542-
543-
return $this->setModified('user_id');
544-
}
545-
546499
/**
547500
* @return int
548501
*

src/Model/Base/BuildError.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
namespace PHPCensor\Model\Base;
66

7-
use DateTime;
8-
use Exception;
97
use PHPCensor\Model;
8+
use PHPCensor\Traits\Model\HasCreateDateTrait;
109

1110
/**
1211
* @package PHP Censor
@@ -17,6 +16,8 @@
1716
*/
1817
class BuildError extends Model
1918
{
19+
use HasCreateDateTrait;
20+
2021
public const SEVERITY_CRITICAL = 0;
2122
public const SEVERITY_HIGH = 1;
2223
public const SEVERITY_NORMAL = 2;
@@ -212,36 +213,6 @@ public function setMessage(string $value)
212213
return $this->setModified('message');
213214
}
214215

215-
/**
216-
* @return DateTime|null
217-
*
218-
* @throws Exception
219-
*/
220-
public function getCreateDate()
221-
{
222-
if ($this->data['create_date']) {
223-
return new DateTime($this->data['create_date']);
224-
}
225-
226-
return null;
227-
}
228-
229-
/**
230-
* @return bool
231-
*/
232-
public function setCreateDate(DateTime $value)
233-
{
234-
$stringValue = $value->format('Y-m-d H:i:s');
235-
236-
if ($this->data['create_date'] === $stringValue) {
237-
return false;
238-
}
239-
240-
$this->data['create_date'] = $stringValue;
241-
242-
return $this->setModified('create_date');
243-
}
244-
245216
/**
246217
* @return string
247218
*/

src/Model/Base/Project.php

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace PHPCensor\Model\Base;
66

7-
use DateTime;
8-
use Exception;
97
use PHPCensor\Common\Exception\InvalidArgumentException;
108
use PHPCensor\Model;
9+
use PHPCensor\Traits\Model\HasCreateDateTrait;
10+
use PHPCensor\Traits\Model\HasUserIdTrait;
1111

1212
/**
1313
* @package PHP Censor
@@ -18,6 +18,9 @@
1818
*/
1919
class Project extends Model
2020
{
21+
use HasCreateDateTrait;
22+
use HasUserIdTrait;
23+
2124
public const TYPE_LOCAL = 'local';
2225
public const TYPE_GIT = 'git';
2326
public const TYPE_GITHUB = 'github';
@@ -392,56 +395,4 @@ public function setGroupId(int $value)
392395

393396
return $this->setModified('group_id');
394397
}
395-
396-
/**
397-
* @return DateTime|null
398-
*
399-
* @throws Exception
400-
*/
401-
public function getCreateDate()
402-
{
403-
if ($this->data['create_date']) {
404-
return new DateTime($this->data['create_date']);
405-
}
406-
407-
return null;
408-
}
409-
410-
/**
411-
* @return bool
412-
*/
413-
public function setCreateDate(DateTime $value)
414-
{
415-
$stringValue = $value->format('Y-m-d H:i:s');
416-
417-
if ($this->data['create_date'] === $stringValue) {
418-
return false;
419-
}
420-
421-
$this->data['create_date'] = $stringValue;
422-
423-
return $this->setModified('create_date');
424-
}
425-
426-
/**
427-
* @return int|null
428-
*/
429-
public function getUserId()
430-
{
431-
return (null !== $this->data['user_id']) ? (int)$this->data['user_id'] : null;
432-
}
433-
434-
/**
435-
* @return bool
436-
*/
437-
public function setUserId(?int $value)
438-
{
439-
if ($this->data['user_id'] === $value) {
440-
return false;
441-
}
442-
443-
$this->data['user_id'] = $value;
444-
445-
return $this->setModified('user_id');
446-
}
447398
}

src/Model/Base/ProjectGroup.php

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace PHPCensor\Model\Base;
66

7-
use DateTime;
8-
use Exception;
97
use PHPCensor\Model;
8+
use PHPCensor\Traits\Model\HasCreateDateTrait;
9+
use PHPCensor\Traits\Model\HasUserIdTrait;
1010

1111
/**
1212
* @package PHP Censor
@@ -16,6 +16,9 @@
1616
*/
1717
class ProjectGroup extends Model
1818
{
19+
use HasCreateDateTrait;
20+
use HasUserIdTrait;
21+
1922
protected array $data = [
2023
'id' => null,
2124
'title' => null,
@@ -66,56 +69,4 @@ public function setTitle(string $value)
6669

6770
return $this->setModified('title');
6871
}
69-
70-
/**
71-
* @return DateTime|null
72-
*
73-
* @throws Exception
74-
*/
75-
public function getCreateDate()
76-
{
77-
if ($this->data['create_date']) {
78-
return new DateTime($this->data['create_date']);
79-
}
80-
81-
return null;
82-
}
83-
84-
/**
85-
* @return bool
86-
*/
87-
public function setCreateDate(DateTime $value)
88-
{
89-
$stringValue = $value->format('Y-m-d H:i:s');
90-
91-
if ($this->data['create_date'] === $stringValue) {
92-
return false;
93-
}
94-
95-
$this->data['create_date'] = $stringValue;
96-
97-
return $this->setModified('create_date');
98-
}
99-
100-
/**
101-
* @return string|null
102-
*/
103-
public function getUserId()
104-
{
105-
return (null !== $this->data['user_id']) ? (int)$this->data['user_id'] : null;
106-
}
107-
108-
/**
109-
* @return bool
110-
*/
111-
public function setUserId(?int $value)
112-
{
113-
if ($this->data['user_id'] === $value) {
114-
return false;
115-
}
116-
117-
$this->data['user_id'] = $value;
118-
119-
return $this->setModified('user_id');
120-
}
12172
}

0 commit comments

Comments
 (0)