-
Notifications
You must be signed in to change notification settings - Fork 1
/
XML.php
42 lines (32 loc) · 967 Bytes
/
XML.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace Babelfish\Strategy;
use Babelfish\File\SourceFile;
use Babelfish\Language;
use function array_slice;
use function assert;
use function implode;
use function strpos;
final class XML implements Strategy
{
private const SEARCH_SCOPE = 2;
/**
* @return Language[]
*/
public function getLanguages(SourceFile $file, Language ...$language_candidates): array
{
if (! empty($language_candidates)) {
return $language_candidates;
}
$header = implode('', array_slice($file->getLines(), 0, self::SEARCH_SCOPE));
if (strpos($header, '<?xml version=') !== false) {
/**
* @see \BabelfishTest\Strategy\XMLTest::testXMLLanguageIsPresent
*/
$xml_language = Language::findByAlias('XML');
assert($xml_language instanceof Language);
return [$xml_language];
}
return [];
}
}