Your project should not change PHP configuration dynamically

More information: https://insight.symfony.com/what-we-analyse/php.dynamically_change_configuration

in makefont/makefont.php, line 439
  1. Message('Font definition file generated: ' . $basename . '.php');
  2. }
  3. if (\PHP_SAPI === 'cli') {
  4. // Command-line interface
  5. \ini_set('log_errors', '0');

    Changing PHP configuration dynamically through ini_set() may create hard to debug errors.

    Time to fix: about 2 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. if (1 === $argc) {
  7. exit("Usage: php makefont.php fontfile [encoding] [embed] [subset]\n");
  8. }
  9. $fontfile = $argv[1];
  10. if ($argc >= 3) {

Your project uses discouraged functions to kill scripts 2

More information: https://insight.symfony.com/what-we-analyse/php.use_exit_function

in makefont/makefont.php, line 48
  1. }
  2. function Error($txt): void
  3. {
  4. Message($txt, 'Error');
  5. exit;

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. }
  7. function LoadMap($enc)
  8. {
  9. $file = __DIR__ . '/' . \strtolower($enc) . '.map';
in makefont/makefont.php, line 441
  1. if (\PHP_SAPI === 'cli') {
  2. // Command-line interface
  3. \ini_set('log_errors', '0');
  4. if (1 === $argc) {
  5. exit("Usage: php makefont.php fontfile [encoding] [embed] [subset]\n");

    This line stops the execution flow, without explanation. If this is for debug, you should remove it. If this is to deal with an error, use exceptions instead.

    Time to fix: about 4 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. }
  7. $fontfile = $argv[1];
  8. if ($argc >= 3) {
  9. $enc = $argv[2];
  10. } else {

Your project should not use too long PHP classes

More information: https://insight.symfony.com/what-we-analyse/php.class_too_long

19% of all classes are larger than 500 lines. Split them up to keep less than 5% large classes.

Time to fix: about 5.1 days
Read doc Open Issue Permalink
Collective

Your project should not use global variables or functions 14

More information: https://insight.symfony.com/what-we-analyse/php.use_global_variable_or_function

in makefont/makefont.php, line 20
  1. * Author: Olivier PLATHEY *
  2. *******************************************************************************/
  3. require 'ttfparser.php';
  4. function Message($txt, $severity = ''): void

    Message() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. if (\PHP_SAPI === 'cli') {
  7. if ($severity) {
  8. echo "$severity: ";
  9. }
in makefont/makefont.php, line 35
  1. }
  2. echo "$txt<br>";
  3. }
  4. }
  5. function Notice($txt): void

    Notice() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. Message($txt, 'Notice');
  8. }
  9. function Warning($txt): void
in makefont/makefont.php, line 40
  1. function Notice($txt): void
  2. {
  3. Message($txt, 'Notice');
  4. }
  5. function Warning($txt): void

    Warning() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. Message($txt, 'Warning');
  8. }
  9. function Error($txt): void
in makefont/makefont.php, line 45
  1. function Warning($txt): void
  2. {
  3. Message($txt, 'Warning');
  4. }
  5. function Error($txt): void

    Error() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. Message($txt, 'Error');
  8. exit;
  9. }
in makefont/makefont.php, line 51
  1. {
  2. Message($txt, 'Error');
  3. exit;
  4. }
  5. function LoadMap($enc)

    LoadMap() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $file = __DIR__ . '/' . \strtolower($enc) . '.map';
  8. $a = \file($file);
  9. if (empty($a)) {
  10. Error('Encoding not found: ' . $enc);
in makefont/makefont.php, line 70
  1. }
  2. return $map;
  3. }
  4. function GetInfoFromTrueType($file, $embed, $subset, $map)

    GetInfoFromTrueType() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. // Return information from a TrueType font
  7. try {
  8. $ttf = new TTFParser($file);
  9. $ttf->Parse();
in makefont/makefont.php, line 126
  1. $info['Widths'] = $widths;
  2. return $info;
  3. }
  4. function GetInfoFromType1($file, $embed, $map)

    GetInfoFromType1() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. // Return information from a Type1 font
  7. if ($embed) {
  8. $f = \fopen($file, 'r');
  9. if (!$f) {
in makefont/makefont.php, line 227
  1. $info['Widths'] = $widths;
  2. return $info;
  3. }
  4. function MakeFontDescriptor($info)

    MakeFontDescriptor() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. // Ascent
  7. $fd = "array('Ascent'=>" . $info['Ascender'];
  8. // Descent
  9. $fd .= ",'Descent'=>" . $info['Descender'];
in makefont/makefont.php, line 269
  1. $fd .= ",'MissingWidth'=>" . $info['MissingWidth'] . ')';
  2. return $fd;
  3. }
  4. function MakeWidthArray($widths)

    MakeWidthArray() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. $s = "array(\n\t";
  7. for ($c = 0; $c <= 255; ++$c) {
  8. if ("'" === \chr($c)) {
  9. $s .= "'\\''";
in makefont/makefont.php, line 295
  1. $s .= ')';
  2. return $s;
  3. }
  4. function MakeFontEncoding($map)

    MakeFontEncoding() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. // Build differences from reference encoding
  7. $ref = LoadMap('cp1252');
  8. $s = '';
  9. $last = 0;
in makefont/makefont.php, line 314
  1. }
  2. return \rtrim($s);
  3. }
  4. function MakeUnicodeArray($map)

    MakeUnicodeArray() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. // Build mapping to Unicode values
  7. $ranges = [];
  8. foreach ($map as $c => $v) {
  9. $uv = $v['uv'];
in makefont/makefont.php, line 355
  1. $s .= ')';
  2. return $s;
  3. }
  4. function SaveToFile($file, $s, $mode): void

    SaveToFile() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. $f = \fopen($file, 'w' . $mode);
  7. if (!$f) {
  8. Error('Can\'t write to file ' . $file);
  9. }
in makefont/makefont.php, line 365
  1. }
  2. \fwrite($f, $s);
  3. \fclose($f);
  4. }
  5. function MakeDefinitionFile($file, $type, $enc, $embed, $subset, $map, $info): void

    MakeDefinitionFile() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $s = "<?php\n";
  8. $s .= '$type = \'' . $type . "';\n";
  9. $s .= '$name = \'' . $info['FontName'] . "';\n";
  10. $s .= '$desc = ' . MakeFontDescriptor($info) . ";\n";
in makefont/makefont.php, line 396
  1. }
  2. $s .= "?>\n";
  3. SaveToFile($file, $s, 't');
  4. }
  5. function MakeFont($fontfile, $enc = 'cp1252', $embed = true, $subset = true): void

    MakeFont() adds to the global scope. Prefer class properties or methods to let other developers know what this relates to.

    Time to fix: about 1 day
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. // Generate a font definition file
  8. if (!\file_exists($fontfile)) {
  9. Error('Font file not found: ' . $fontfile);
  10. }

Your project should not contain duplicated code 4

More information: https://insight.symfony.com/what-we-analyse/php.duplicated_code

  1. <?php
  2. $type = 'Core';
  3. $name = 'Courier';
  4. $up = -100;

    The next 6 lines appear in src/font/courier.php:4, src/font/courierb.php:4, src/font/courierbi.php:4 and src/font/courieri.php:4.

    Time to fix: about 4 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. $ut = 50;
  6. for($i=0;$i<=255;$i++)
  7. $cw[chr($i)] = 600;
  8. $enc = 'cp1252';
  9. $uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
  1. <?php
  2. $type = 'Core';
  3. $name = 'Helvetica';
  4. $up = -100;

    The next 17 lines appear in src/font/helvetica.php:4, src/font/helveticabi.php:4 and src/font/helveticai.php:4.

    Time to fix: about 4 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. $ut = 50;
  6. $cw = array(
  7. chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
  8. chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584,
  9. ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667,
  1. <?php
  2. $type = 'Core';
  3. $name = 'Helvetica';
  4. $up = -100;

    The next 5 lines appear both in src/font/helvetica.php:4 and src/font/helveticab.php:4.

    Time to fix: about 4 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. $ut = 50;
  6. $cw = array(
  7. chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
  8. chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584,
  9. ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667,
in src/font/symbol.php, line 4
  1. <?php
  2. $type = 'Core';
  3. $name = 'Symbol';
  4. $up = -100;

    The next 5 lines appear in src/font/symbol.php:4, src/font/times.php:4, src/font/timesb.php:4, src/font/timesbi.php:4 and src/font/timesi.php:4.

    Time to fix: about 4 hours
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. $ut = 50;
  6. $cw = array(
  7. chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250,
  8. chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549,
  9. ','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722,

The code of your project must follow PSR-1 basic coding standard 34

More information: https://insight.symfony.com/what-we-analyse/php.psr1

  1. * Version: 1.11 *
  2. * Date: 2021-04-18 *
  3. * Author: Olivier PLATHEY *
  4. *******************************************************************************/
  5. class ttfparser

    Class names should be declared in StudlyCaps.
    You should rename this class to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. public $bold;
  8. public $capHeight;
  9. public $chars;
  10. public $embeddable;
  1. if (\is_resource($this->f)) {
  2. \fclose($this->f);
  3. }
  4. }
  5. public function AddGlyph($id): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. if (!isset($this->glyphs[$id]['ssid'])) {
  8. $this->glyphs[$id]['ssid'] = \count($this->subsettedGlyphs);
  9. $this->subsettedGlyphs[] = $id;
  10. if (isset($this->glyphs[$id]['components'])) {
  1. }
  2. }
  3. }
  4. }
  5. public function Build()

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->BuildCmap();
  8. $this->BuildHhea();
  9. $this->BuildHmtx();
  10. $this->BuildLoca();
  1. $this->BuildPost();
  2. return $this->BuildFont();
  3. }
  4. public function BuildCmap(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. if (!isset($this->subsettedChars)) {
  7. return;
  8. }
in makefont/ttfparser.php, line 170
  1. $data .= \pack('nnn', 4, 6 + \strlen($cmap), 0); // format, length, language
  2. $data .= $cmap;
  3. $this->SetTable('cmap', $data);
  4. }
  5. public function BuildFont()

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $tags = [];
  8. foreach (['cmap', 'cvt ', 'fpgm', 'glyf', 'head', 'hhea', 'hmtx', 'loca', 'maxp', 'name', 'post', 'prep'] as $tag) {
  9. if (isset($this->tables[$tag])) {
  10. $tags[] = $tag;
in makefont/ttfparser.php, line 222
  1. }
  2. return $font;
  3. }
  4. public function BuildGlyf(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. $tableOffset = $this->tables['glyf']['offset'];
  7. $data = '';
  8. foreach ($this->subsettedGlyphs as $id) {
  9. $glyph = $this->glyphs[$id];
in makefont/ttfparser.php, line 242
  1. $data .= $glyph_data;
  2. }
  3. $this->SetTable('glyf', $data);
  4. }
  5. public function BuildHhea(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->LoadTable('hhea');
  8. $numberOfHMetrics = \count($this->subsettedGlyphs);
  9. $data = \substr_replace($this->tables['hhea']['data'], \pack('n', $numberOfHMetrics), 4 + 15 * 2, 2);
  10. $this->SetTable('hhea', $data);
in makefont/ttfparser.php, line 250
  1. $numberOfHMetrics = \count($this->subsettedGlyphs);
  2. $data = \substr_replace($this->tables['hhea']['data'], \pack('n', $numberOfHMetrics), 4 + 15 * 2, 2);
  3. $this->SetTable('hhea', $data);
  4. }
  5. public function BuildHmtx(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $data = '';
  8. foreach ($this->subsettedGlyphs as $id) {
  9. $glyph = $this->glyphs[$id];
  10. $data .= \pack('nn', $glyph['w'], $glyph['lsb']);
in makefont/ttfparser.php, line 260
  1. $data .= \pack('nn', $glyph['w'], $glyph['lsb']);
  2. }
  3. $this->SetTable('hmtx', $data);
  4. }
  5. public function BuildLoca(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $data = '';
  8. $offset = 0;
  9. foreach ($this->subsettedGlyphs as $id) {
  10. if (0 === $this->indexToLocFormat) {
in makefont/ttfparser.php, line 280
  1. $data .= \pack('N', $offset);
  2. }
  3. $this->SetTable('loca', $data);
  4. }
  5. public function BuildMaxp(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->LoadTable('maxp');
  8. $numGlyphs = \count($this->subsettedGlyphs);
  9. $data = \substr_replace($this->tables['maxp']['data'], \pack('n', $numGlyphs), 4, 2);
  10. $this->SetTable('maxp', $data);
in makefont/ttfparser.php, line 288
  1. $numGlyphs = \count($this->subsettedGlyphs);
  2. $data = \substr_replace($this->tables['maxp']['data'], \pack('n', $numGlyphs), 4, 2);
  3. $this->SetTable('maxp', $data);
  4. }
  5. public function BuildPost(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('post');
  8. if ($this->glyphNames) {
  9. // Version 2.0
  10. $numberOfGlyphs = \count($this->subsettedGlyphs);
in makefont/ttfparser.php, line 318
  1. $data .= $this->Read(4 + 2 * 2 + 5 * 4);
  2. }
  3. $this->SetTable('post', $data);
  4. }
  5. public function CheckSum($s)

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $n = \strlen($s);
  8. $high = 0;
  9. $low = 0;
  10. for ($i = 0; $i < $n; $i += 4) {
in makefont/ttfparser.php, line 331
  1. }
  2. return \pack('nn', $high + ($low >> 16), $low);
  3. }
  4. public function Error($msg): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. throw new Exception($msg);
  7. }
  8. public function LoadTable($tag): void
in makefont/ttfparser.php, line 336
  1. public function Error($msg): void
  2. {
  3. throw new Exception($msg);
  4. }
  5. public function LoadTable($tag): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek($tag);
  8. $length = $this->tables[$tag]['length'];
  9. $n = $length % 4;
  10. if ($n > 0) {
in makefont/ttfparser.php, line 347
  1. $length += 4 - $n;
  2. }
  3. $this->tables[$tag]['data'] = $this->Read($length);
  4. }
  5. public function Parse(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->ParseOffsetTable();
  8. $this->ParseHead();
  9. $this->ParseHhea();
  10. $this->ParseMaxp();
in makefont/ttfparser.php, line 362
  1. $this->ParseName();
  2. $this->ParseOS2();
  3. $this->ParsePost();
  4. }
  5. public function ParseCmap(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('cmap');
  8. $this->Skip(2); // version
  9. $numTables = $this->ReadUShort();
  10. $offset31 = 0;
in makefont/ttfparser.php, line 438
  1. }
  2. }
  3. }
  4. }
  5. public function ParseGlyf(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $tableOffset = $this->tables['glyf']['offset'];
  8. foreach ($this->glyphs as &$glyph) {
  9. if ($glyph['length'] > 0) {
  10. \fseek($this->f, $tableOffset + $glyph['offset'], \SEEK_SET);
in makefont/ttfparser.php, line 474
  1. }
  2. }
  3. }
  4. }
  5. public function ParseHead(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('head');
  8. $this->Skip(3 * 4); // version, fontRevision, checkSumAdjustment
  9. $magicNumber = $this->ReadULong();
  10. if (0x5F0F3CF5 !== $magicNumber) {
in makefont/ttfparser.php, line 493
  1. $this->yMax = $this->ReadShort();
  2. $this->Skip(3 * 2); // macStyle, lowestRecPPEM, fontDirectionHint
  3. $this->indexToLocFormat = $this->ReadShort();
  4. }
  5. public function ParseHhea(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('hhea');
  8. $this->Skip(4 + 15 * 2);
  9. $this->numberOfHMetrics = $this->ReadUShort();
  10. }
in makefont/ttfparser.php, line 500
  1. $this->Seek('hhea');
  2. $this->Skip(4 + 15 * 2);
  3. $this->numberOfHMetrics = $this->ReadUShort();
  4. }
  5. public function ParseHmtx(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('hmtx');
  8. $this->glyphs = [];
  9. for ($i = 0; $i < $this->numberOfHMetrics; ++$i) {
  10. $advanceWidth = $this->ReadUShort();
in makefont/ttfparser.php, line 515
  1. $lsb = $this->ReadShort();
  2. $this->glyphs[$i] = ['w' => $advanceWidth, 'lsb' => $lsb];
  3. }
  4. }
  5. public function ParseLoca(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('loca');
  8. $offsets = [];
  9. if (0 === $this->indexToLocFormat) {
  10. // Short format
in makefont/ttfparser.php, line 536
  1. $this->glyphs[$i]['offset'] = $offsets[$i];
  2. $this->glyphs[$i]['length'] = $offsets[$i + 1] - $offsets[$i];
  3. }
  4. }
  5. public function ParseMaxp(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('maxp');
  8. $this->Skip(4);
  9. $this->numGlyphs = $this->ReadUShort();
  10. }
in makefont/ttfparser.php, line 543
  1. $this->Seek('maxp');
  2. $this->Skip(4);
  3. $this->numGlyphs = $this->ReadUShort();
  4. }
  5. public function ParseName(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('name');
  8. $tableOffset = $this->tables['name']['offset'];
  9. $this->postScriptName = '';
  10. $this->Skip(2); // format
in makefont/ttfparser.php, line 571
  1. if ('' === $this->postScriptName) {
  2. $this->Error('PostScript name not found');
  3. }
  4. }
  5. public function ParseOffsetTable(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $version = $this->Read(4);
  8. if ('OTTO' === $version) {
  9. $this->Error('OpenType fonts based on PostScript outlines are not supported');
  10. }
in makefont/ttfparser.php, line 592
  1. $length = $this->ReadULong();
  2. $this->tables[$tag] = ['offset' => $offset, 'length' => $length, 'checkSum' => $checkSum];
  3. }
  4. }
  5. public function ParseOS2(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('OS/2');
  8. $version = $this->ReadUShort();
  9. $this->Skip(3 * 2); // xAvgCharWidth, usWeightClass, usWidthClass
  10. $fsType = $this->ReadUShort();
in makefont/ttfparser.php, line 613
  1. } else {
  2. $this->capHeight = 0;
  3. }
  4. }
  5. public function ParsePost(): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->Seek('post');
  8. $version = $this->ReadULong();
  9. $this->italicAngle = $this->ReadShort();
  10. $this->Skip(2); // Skip decimal part
in makefont/ttfparser.php, line 653
  1. } else {
  2. $this->glyphNames = false;
  3. }
  4. }
  5. public function Read($n)

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. return $n > 0 ? \fread($this->f, $n) : '';
  8. }
  9. public function ReadShort()
in makefont/ttfparser.php, line 658
  1. public function Read($n)
  2. {
  3. return $n > 0 ? \fread($this->f, $n) : '';
  4. }
  5. public function ReadShort()

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $a = \unpack('nn', \fread($this->f, 2));
  8. $v = $a['n'];
  9. if ($v >= 0x8000) {
  10. $v -= 65536;
in makefont/ttfparser.php, line 669
  1. }
  2. return $v;
  3. }
  4. public function ReadULong()

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. $a = \unpack('NN', \fread($this->f, 4));
  7. return $a['N'];
  8. }
in makefont/ttfparser.php, line 676
  1. $a = \unpack('NN', \fread($this->f, 4));
  2. return $a['N'];
  3. }
  4. public function ReadUShort()

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. $a = \unpack('nn', \fread($this->f, 2));
  7. return $a['n'];
  8. }
in makefont/ttfparser.php, line 683
  1. $a = \unpack('nn', \fread($this->f, 2));
  2. return $a['n'];
  3. }
  4. public function Seek($tag): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  5. {
  6. if (!isset($this->tables[$tag])) {
  7. $this->Error('Table not found: ' . $tag);
  8. }
  9. \fseek($this->f, $this->tables[$tag]['offset'], \SEEK_SET);
in makefont/ttfparser.php, line 691
  1. $this->Error('Table not found: ' . $tag);
  2. }
  3. \fseek($this->f, $this->tables[$tag]['offset'], \SEEK_SET);
  4. }
  5. public function SetTable($tag, $data): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $length = \strlen($data);
  8. $n = $length % 4;
  9. if ($n > 0) {
  10. $data = \str_pad($data, $length + 4 - $n, "\x00");
in makefont/ttfparser.php, line 703
  1. $this->tables[$tag]['data'] = $data;
  2. $this->tables[$tag]['length'] = $length;
  3. $this->tables[$tag]['checkSum'] = $this->CheckSum($data);
  4. }
  5. public function Skip($n): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. \fseek($this->f, $n, \SEEK_CUR);
  8. }
  9. public function Subset($chars): void
in makefont/ttfparser.php, line 708
  1. public function Skip($n): void
  2. {
  3. \fseek($this->f, $n, \SEEK_CUR);
  4. }
  5. public function Subset($chars): void

    Method names should be declared in camelCase.
    You should rename this method to comply with PSR-1.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  6. {
  7. $this->subsettedGlyphs = [];
  8. $this->AddGlyph(0);
  9. $this->subsettedChars = [];
  10. foreach ($chars as $char) {

Your project should not use function in loops conditions

More information: https://insight.symfony.com/what-we-analyse/php.for_loop_uses_test_function

  1. // Divide charset in contiguous segments
  2. $chars = $this->subsettedChars;
  3. \sort($chars);
  4. $segments = [];
  5. $segment = [$chars[0], $chars[0]];
  6. for ($i = 1; $i < \count($chars); ++$i) {

    This loop uses a function. To avoid the overhead of executing the function n times, you should precalculate it before the loop.

    Time to fix: about 15 minutes
    Read doc Open Issue Permalink
    Last edited by Laurent Muller
  7. if ($chars[$i] > $segment[1] + 1) {
  8. $segments[] = $segment;
  9. $segment = [$chars[$i], $chars[$i]];
  10. } else {
  11. ++$segment[1];