getInitialByteSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of SwiftMailer.
5
 * (c) 2004-2009 Chris Corbyn
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * Analyzes US-ASCII characters.
13
 *
14
 * @author Chris Corbyn
15
 */
16
class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    /**
19
     * Returns the complete character map.
20
     *
21
     * @param string $string
22
     * @param int    $startOffset
23
     * @param array  $currentMap
24
     * @param string $ignoredChars
25
     *
26
     * @return int
27
     */
28
    public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars): int
29
    {
30
        $strlen = strlen($string);
31
        $ignoredChars = '';
32
        for ($i = 0; $i < $strlen; ++$i) {
33
            if ($string[$i] > "\x07F") {
34
                // Invalid char
35
                $currentMap[$i + $startOffset] = $string[$i];
36
            }
37
        }
38
39
        return $strlen;
40
    }
41
42
    /**
43
     * Returns mapType.
44
     *
45
     * @return int mapType
46
     */
47
    public function getMapType(): int
48
    {
49
        return self::MAP_TYPE_INVALID;
50
    }
51
52
    /**
53
     * Returns an integer which specifies how many more bytes to read.
54
     *
55
     * A positive integer indicates the number of more bytes to fetch before invoking
56
     * this method again.
57
     * A value of zero means this is already a valid character.
58
     * A value of -1 means this cannot possibly be a valid character.
59
     *
60
     * @param string $bytes
61
     * @param int    $size
62
     *
63
     * @return int
64
     */
65 3
    public function validateByteSequence($bytes, $size): int
66
    {
67 3
        $byte = reset($bytes);
68
        if (
69 3
            1 === count($bytes)
70 3
            &&
71
            $byte >= 0x00
72 3
            &&
73
            $byte <= 0x7F
74 3
        ) {
75 1
            return 0;
76
        }
77
78 2
        return -1;
79
    }
80
81
    /**
82
     * Returns the number of bytes which should be read to start each character.
83
     *
84
     * @return int
85
     */
86
    public function getInitialByteSize(): int
87
    {
88
        return 1;
89
    }
90
}
91