Issues (38)

src/Collections/Transcript.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Transcript
4
 *
5
 * @package LivePersonInc\LiveEngageLaravel\Collections
6
 */
7
8
namespace LivePersonInc\LiveEngageLaravel\Collections;
9
10
use Illuminate\Support\Collection;
11
use LivePersonInc\LiveEngageLaravel\Models\Message;
12
use LivePersonInc\LiveEngageLaravel\Models\Agent;
13
14
/**
15
 * Transcript class.
16
 * 
17
 * @extends Collection
18
 */
19
class Transcript extends Collection
20
{
21 2
	public function __construct(array $models = [], $agents = false)
22
	{
23
		$models = array_map(function($item) use ($agents) {
24 2
			if (property_exists($item, 'sentBy') && $item->sentBy == 'Agent' && $agents) {
25 1
				$item->agentDetails = $agents->findById($item->participantId);
26
			}
27 2
			return new Message((array) $item);
28 2
		}, $models);
29 2
		return parent::__construct($models);
0 ignored issues
show
Are you sure the usage of parent::__construct($models) targeting Illuminate\Support\Collection::__construct() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
30
	}
31
	
32
	public function textTranscript()
33
	{
34
		$text = "";
35
		foreach ($this as $message) {
36
			$by = $message->sentBy == 'Agent' ? $message->agentDetails->agentFullName : 'Visitor';
37
			$text .= "{$by}:\n{$message->plainText}\n\n";
38
		}
39
		return $text;
40
	}
41
}
42