Passed
Push — master ( 887396...ef87df )
by Blizzz
16:21 queued 21s
created
lib/private/Comments/Manager.php 1 patch
Indentation   +1627 added lines, -1627 removed lines patch added patch discarded remove patch
@@ -47,1631 +47,1631 @@
 block discarded – undo
47 47
 use Psr\Log\LoggerInterface;
48 48
 
49 49
 class Manager implements ICommentsManager {
50
-	/** @var  IDBConnection */
51
-	protected $dbConn;
52
-
53
-	/** @var  LoggerInterface */
54
-	protected $logger;
55
-
56
-	/** @var IConfig */
57
-	protected $config;
58
-
59
-	/** @var ITimeFactory */
60
-	protected $timeFactory;
61
-
62
-	/** @var IEmojiHelper */
63
-	protected $emojiHelper;
64
-
65
-	/** @var IInitialStateService */
66
-	protected $initialStateService;
67
-
68
-	/** @var IComment[] */
69
-	protected $commentsCache = [];
70
-
71
-	/** @var  \Closure[] */
72
-	protected $eventHandlerClosures = [];
73
-
74
-	/** @var  ICommentsEventHandler[] */
75
-	protected $eventHandlers = [];
76
-
77
-	/** @var \Closure[] */
78
-	protected $displayNameResolvers = [];
79
-
80
-	public function __construct(IDBConnection $dbConn,
81
-								LoggerInterface $logger,
82
-								IConfig $config,
83
-								ITimeFactory $timeFactory,
84
-								IEmojiHelper $emojiHelper,
85
-								IInitialStateService $initialStateService) {
86
-		$this->dbConn = $dbConn;
87
-		$this->logger = $logger;
88
-		$this->config = $config;
89
-		$this->timeFactory = $timeFactory;
90
-		$this->emojiHelper = $emojiHelper;
91
-		$this->initialStateService = $initialStateService;
92
-	}
93
-
94
-	/**
95
-	 * converts data base data into PHP native, proper types as defined by
96
-	 * IComment interface.
97
-	 *
98
-	 * @param array $data
99
-	 * @return array
100
-	 */
101
-	protected function normalizeDatabaseData(array $data) {
102
-		$data['id'] = (string)$data['id'];
103
-		$data['parent_id'] = (string)$data['parent_id'];
104
-		$data['topmost_parent_id'] = (string)$data['topmost_parent_id'];
105
-		$data['creation_timestamp'] = new \DateTime($data['creation_timestamp']);
106
-		if (!is_null($data['latest_child_timestamp'])) {
107
-			$data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']);
108
-		}
109
-		if (!is_null($data['expire_date'])) {
110
-			$data['expire_date'] = new \DateTime($data['expire_date']);
111
-		}
112
-		$data['children_count'] = (int)$data['children_count'];
113
-		$data['reference_id'] = $data['reference_id'] ?? null;
114
-		if ($this->supportReactions()) {
115
-			if ($data['reactions'] !== null) {
116
-				$list = json_decode($data['reactions'], true);
117
-				// Ordering does not work on the database with group concat and Oracle,
118
-				// So we simply sort on the output.
119
-				if (is_array($list)) {
120
-					uasort($list, static function ($a, $b) {
121
-						if ($a === $b) {
122
-							return 0;
123
-						}
124
-						return ($a > $b) ? -1 : 1;
125
-					});
126
-					$data['reactions'] = $list;
127
-				} else {
128
-					$data['reactions'] = [];
129
-				}
130
-			} else {
131
-				$data['reactions'] = [];
132
-			}
133
-		}
134
-		return $data;
135
-	}
136
-
137
-
138
-	/**
139
-	 * @param array $data
140
-	 * @return IComment
141
-	 */
142
-	public function getCommentFromData(array $data): IComment {
143
-		return new Comment($this->normalizeDatabaseData($data));
144
-	}
145
-
146
-	/**
147
-	 * prepares a comment for an insert or update operation after making sure
148
-	 * all necessary fields have a value assigned.
149
-	 *
150
-	 * @param IComment $comment
151
-	 * @return IComment returns the same updated IComment instance as provided
152
-	 *                  by parameter for convenience
153
-	 * @throws \UnexpectedValueException
154
-	 */
155
-	protected function prepareCommentForDatabaseWrite(IComment $comment) {
156
-		if (!$comment->getActorType()
157
-			|| $comment->getActorId() === ''
158
-			|| !$comment->getObjectType()
159
-			|| $comment->getObjectId() === ''
160
-			|| !$comment->getVerb()
161
-		) {
162
-			throw new \UnexpectedValueException('Actor, Object and Verb information must be provided for saving');
163
-		}
164
-
165
-		if ($comment->getVerb() === 'reaction' && !$this->emojiHelper->isValidSingleEmoji($comment->getMessage())) {
166
-			// 4 characters: laptop + person + gender + skin color => "
Please login to merge, or discard this patch.