TrashItem::getCollectionName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Model;
15
16
use Maslosoft\Mangan\Document;
17
use Maslosoft\Mangan\Interfaces\TrashInterface;
18
use Maslosoft\Mangan\Sanitizers\DateSanitizer;
19
use Maslosoft\Mangan\Traits\Model\TrashableTrait;
20
use MongoDate;
21
22
/**
23
 * TrashItem
24
 *
25
 * @Label('Trashed item')
26
 * @author Piotr
27
 */
28
class TrashItem extends Document implements TrashInterface
29
{
30
31
	use TrashableTrait;
32
33
	/**
34
	 * Element name
35
	 * @Label('Name')
36
	 * @var string
37
	 */
38
	public $name = '';
39
40
	/**
41
	 * Type of trashed item
42
	 * @Label('Type')
43
	 * @var string
44
	 */
45
	public $type = '';
46
47
	/**
48
	 * When it was trashed.
49
	 * @Sanitizer(DateSanitizer)
50
	 * @see DateSanitizer
51
	 * @var MongoDate
52
	 */
53
	public $createDate = '';
54
55 1
	public function getCollectionName()
56
	{
57 1
		return 'Mangan.Trash';
58
	}
59
60
	/**
61
	 * Purge all items from trash. Returns number of removed items.
62
	 * @return int
63
	 */
64 1
	public function purge()
65
	{
66 1
		$removed = 0;
67
		// Remove with loop to fire before/afterDelete events
68 1
		foreach ($this->findAll() as $trash)
69
		{
70 1
			if ($trash->delete())
71
			{
72 1
				$removed++;
73
			}
74
		}
75 1
		return $removed;
76
	}
77
78
	public function __toString()
79
	{
80
		return 'Trashed';
81
	}
82
83
}
84