Completed
Push — master ( 820ca9...637b42 )
by Rudie
02:13
created

IMAPMessageContent   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A allParts() 0 20 4
A part() 0 4 1
A parameters() 0 16 4
A parameter() 0 4 1
1
<?php
2
3
namespace rdx\imap;
4
5
abstract class IMAPMessageContent {
6
7
	protected $structure; // stdClass
8
	protected $parts = []; // Array<rdx\imap\IMAPMessagePart>
9
	protected $parameters = [];
10
11
	public function allParts( $withContainers = false ) {
12
		$parts = [];
13
		$iterate = function($message) use (&$iterate, &$parts, $withContainers) {
14
			foreach ( $message->parts() as $part ) {
15
				if ( $part->parts() ) {
16
					if ( $withContainers ) {
17
						$parts[] = $part;
18
					}
19
20
					$iterate($part);
21
				}
22
				else {
23
					$parts[] = $part;
24
				}
25
			}
26
		};
27
28
		$iterate($this);
29
		return $parts;
30
	}
31
32
	public function part( $index ) {
33
		$parts = $this->parts();
34
		return @$parts[$index];
35
	}
36
37
	public function parameters() {
38
		if ( empty($this->parameters) ) {
39
			$structure = $this->structure();
40
41
			$this->parameters['bytes'] = @$structure->bytes;
42
43
			foreach ((array) @$structure->parameters as $param) {
44
				$this->parameters[ strtolower($param->attribute) ] = $param->value;
45
			}
46
			foreach ((array) @$structure->dparameters as $param) {
47
				$this->parameters[ strtolower($param->attribute) ] = $param->value;
48
			}
49
		}
50
51
		return $this->parameters;
52
	}
53
54
	public function parameter( $name ) {
55
		$parameters = $this->parameters();
56
		return @$parameters[ strtolower($name) ];
57
	}
58
59
}
60