Announcement::propertyToColumn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2019 Joas Schilling <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\AnnouncementCenter\Model;
24
25
26
use OCP\AppFramework\Db\Entity;
27
28
/**
29
 * @method void setTime(int $time)
30
 * @method int getTime()
31
 * @method void setUser(string $user)
32
 * @method string getUser()
33
 * @method void setSubject(string $subject)
34
 * @method void setMessage(string $message)
35
 * @method string getMessage()
36
 * @method void setAllowComments(int $allowComments)
37
 * @method int getAllowComments()
38
 */
39
class Announcement extends Entity {
40
41
	/** @var int */
42
	protected $time;
43
44
	/** @var string */
45
	protected $user;
46
47
	/** @var string */
48
	protected $subject;
49
50
	/** @var string */
51
	protected $message;
52
53
	/** @var int */
54
	protected $allowComments;
55
56 9
	public function __construct() {
57 9
		$this->addType('time', 'int');
58 9
		$this->addType('user', 'string');
59 9
		$this->addType('subject', 'string');
60 9
		$this->addType('message', 'string');
61 9
		$this->addType('allowComments', 'int');
62 9
	}
63
64
	public function getSubject(): string {
65
		return trim(str_replace("\n", ' ', parent::getSubject()));
66
	}
67
68
	public function getParsedMessage(): string {
69
		return str_replace(['<', '>', "\n"], ['&lt;', '&gt;', '<br />'], parent::getMessage());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getMessage() instead of getParsedMessage()). Are you sure this is correct? If so, you might want to change this to $this->getMessage().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
70
	}
71
72
	/**
73
	 * @param string $columnName the name of the column
74
	 * @return string the property name
75
	 */
76
	public function columnToProperty($columnName): string {
77
		// Strip off announcement_
78
		if (strpos($columnName, 'announcement_') === 0) {
79
			$columnName = substr($columnName, strlen('announcement_'));
80
		}
81
82
		return parent::columnToProperty($columnName);
83
	}
84
85
	/**
86
	 * @param string $property the name of the property
87
	 * @return string the column name
88
	 */
89
	public function propertyToColumn($property): string {
90
		if ($property !== 'allowComments') {
91
			$property = 'announcement' . ucfirst($property);
92
		}
93
94
		return parent::propertyToColumn($property);
95
	}
96
}
97