3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace FlatFileParser; $definitions = [ ['name' => 'Serial Number', 'length' => 16, 'type' => 'int'], ['name' => 'Language', 'length' => 3, 'type' => 'string'], ['name' => 'Business Name', 'length' => 32, 'type' => 'string'], ['name' => 'Business Code', 'length' => 8, 'type' => 'string'], ['name' => 'Authorization Code', 'length' => 8, 'type' => 'string'], ['name' => 'Timestamp', 'length' => 20, 'type' => 'timestamp'], ]; $writer = new Writer(); $validator = new Validator(); $parser = new Parser(); if(count($argv) != 2){ $writer->write("ERROR: No flat file provided"); } try{ $data = new SplFileObject($argv[1]); if ($data->isFile() && $data->isReadable()) { $lineNumber = 1; while (!$file->eof()) { $line = $file->fgets(); if($validator->isValidLineLength($line)){ $business = convertLineToBusiness($line); $writer->writeBusiness($business); } else{ $writer->write("Line Number: " + $lineNumber + "ERROR: Line to Long"); } $lineNumber ++; } } else{ $writer->write("ERROR: Flat file not readable"); } } catch(Exception $e){ echo "err"; } class Writer{ public function write($text){ echo $text . "\n"; } public function writeBusiness($lineNumber, $business){ write("Line Number: " + $lineNumber); write("Serial Number: " + $business->serialNumber); write("Language: " + $business->language); write("Business Name: " + $business->businessName); write("Business Code: " + $business->businessCode); write("Authorization Code: " + $business->get(authorizationCode)); write("Timestamp: " + $business->timestamp); } } class Validator{ private $validLineLength; public function isValidLineLength($line){ return strlen($line) < $this->validLineLength; } function Validator(){ $this->validLineLength = 0; foreach($definitions as $definition){ $this->validLineLength += $definition->length; } } } class Parser{ public function convertLineToBusiness($line){ $start = 0; $parms = []; foreach($definitions as $definition){ array_push($parms, substr($line, $start, $definition->length)); $start += $definition->length; } return new Business($parms); } } class Business{ public $serialNumber; public $language; public $businessName; public $businessCode; private $authorizationCode; public $timestamp; /** * Getter for some private attributes * @return mixed $attribute */ public function __get($attribute){ if (isset($this->{"_".$attribute})){ return $this->{"_".$attribute}; } else{ return false; } } public function Business($parms){ $this->serialNumber = $parms[1]; $this->language = $parms[2]; $this->businessName = $parms[3]; $this->businessCode = $parms[4]; $this->authorizationCode = $parms[5]; $this->timestamp = $parms[6]; } } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 59
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 33
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 48
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 33
Branch analysis from position: 58
Branch analysis from position: 33
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 33
Branch analysis from position: 58
Branch analysis from position: 33
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
Branch analysis from position: 30
Branch analysis from position: 18
Found catch point at position: 63
Branch analysis from position: 63
2 jumps found. (Code = 107) Position 1 = 64, Position 2 = -2
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGChT
function name:  (null)
number of ops:  66
compiled vars:  !0 = $definitions, !1 = $writer, !2 = $validator, !3 = $parser, !4 = $argv, !5 = $data, !6 = $lineNumber, !7 = $line, !8 = $file, !9 = $business, !10 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        NEW                                              $12     'FlatFileParser%5CWriter'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $12
   13     4        NEW                                              $15     'FlatFileParser%5CValidator'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $15
   14     7        NEW                                              $18     'FlatFileParser%5CParser'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $18
   15    10        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Ccount'
         11        SEND_VAR_EX                                              !4
         12        DO_FCALL                                      0  $21     
         13        IS_NOT_EQUAL                                             $21, 2
         14      > JMPZ                                                     ~22, ->18
   16    15    >   INIT_METHOD_CALL                                         !1, 'write'
         16        SEND_VAL_EX                                              'ERROR%3A+No+flat+file+provided'
         17        DO_FCALL                                      0          
   19    18    >   NEW                                              $24     'FlatFileParser%5CSplFileObject'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $25     !4, 1
         21        SEND_FUNC_ARG                                            $25
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !5, $24
   20    24        INIT_METHOD_CALL                                         !5, 'isFile'
         25        DO_FCALL                                      0  $28     
         26      > JMPZ_EX                                          ~29     $28, ->30
         27    >   INIT_METHOD_CALL                                         !5, 'isReadable'
         28        DO_FCALL                                      0  $30     
         29        BOOL                                             ~29     $30
         30    > > JMPZ                                                     ~29, ->59
   21    31    >   ASSIGN                                                   !6, 1
   22    32      > JMP                                                      ->54
   23    33    >   INIT_METHOD_CALL                                         !8, 'fgets'
         34        DO_FCALL                                      0  $32     
         35        ASSIGN                                                   !7, $32
   24    36        INIT_METHOD_CALL                                         !2, 'isValidLineLength'
         37        SEND_VAR_EX                                              !7
         38        DO_FCALL                                      0  $34     
         39      > JMPZ                                                     $34, ->48
   25    40    >   INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5CconvertLineToBusiness'
         41        SEND_VAR_EX                                              !7
         42        DO_FCALL                                      0  $35     
         43        ASSIGN                                                   !9, $35
   26    44        INIT_METHOD_CALL                                         !1, 'writeBusiness'
         45        SEND_VAR_EX                                              !9
         46        DO_FCALL                                      0          
         47      > JMP                                                      ->53
   29    48    >   INIT_METHOD_CALL                                         !1, 'write'
         49        ADD                                              ~38     'Line+Number%3A+', !6
         50        ADD                                              ~39     ~38, 'ERROR%3A+Line+to+Long'
         51        SEND_VAL_EX                                              ~39
         52        DO_FCALL                                      0          
   31    53    >   PRE_INC                                                  !6
   22    54    >   INIT_METHOD_CALL                                         !8, 'eof'
         55        DO_FCALL                                      0  $42     
         56        BOOL_NOT                                         ~43     $42
         57      > JMPNZ                                                    ~43, ->33
         58    > > JMP                                                      ->62
   35    59    >   INIT_METHOD_CALL                                         !1, 'write'
         60        SEND_VAL_EX                                              'ERROR%3A+Flat+file+not+readable'
         61        DO_FCALL                                      0          
         62    > > JMP                                                      ->65
   38    63  E > > CATCH                                       last         'FlatFileParser%5CException'
   39    64    >   ECHO                                                     'err'
  125    65    > > RETURN                                                   1

Class FlatFileParser\Writer:
Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGChT
function name:  write
number of ops:  4
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        CONCAT                                           ~1      !0, '%0A'
          2        ECHO                                                     ~1
   47     3      > RETURN                                                   null

End of function write

Function writebusiness:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGChT
function name:  writeBusiness
number of ops:  40
compiled vars:  !0 = $lineNumber, !1 = $business
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
          3        ADD                                              ~2      'Line+Number%3A+', !0
          4        SEND_VAL_EX                                              ~2
          5        DO_FCALL                                      0          
   51     6        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
          7        FETCH_OBJ_R                                      ~4      !1, 'serialNumber'
          8        ADD                                              ~5      'Serial+Number%3A+', ~4
          9        SEND_VAL_EX                                              ~5
         10        DO_FCALL                                      0          
   52    11        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
         12        FETCH_OBJ_R                                      ~7      !1, 'language'
         13        ADD                                              ~8      'Language%3A+', ~7
         14        SEND_VAL_EX                                              ~8
         15        DO_FCALL                                      0          
   53    16        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
         17        FETCH_OBJ_R                                      ~10     !1, 'businessName'
         18        ADD                                              ~11     'Business+Name%3A+', ~10
         19        SEND_VAL_EX                                              ~11
         20        DO_FCALL                                      0          
   54    21        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
         22        FETCH_OBJ_R                                      ~13     !1, 'businessCode'
         23        ADD                                              ~14     'Business+Code%3A+', ~13
         24        SEND_VAL_EX                                              ~14
         25        DO_FCALL                                      0          
   55    26        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
         27        INIT_METHOD_CALL                                         !1, 'get'
         28        FETCH_CONSTANT                                   ~16     'FlatFileParser%5CauthorizationCode'
         29        SEND_VAL_EX                                              ~16
         30        DO_FCALL                                      0  $17     
         31        ADD                                              ~18     'Authorization+Code%3A+', $17
         32        SEND_VAL_EX                                              ~18
         33        DO_FCALL                                      0          
   56    34        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cwrite'
         35        FETCH_OBJ_R                                      ~20     !1, 'timestamp'
         36        ADD                                              ~21     'Timestamp%3A+', ~20
         37        SEND_VAL_EX                                              ~21
         38        DO_FCALL                                      0          
   57    39      > RETURN                                                   null

End of function writebusiness

End of class FlatFileParser\Writer.

Class FlatFileParser\Validator:
Function isvalidlinelength:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGChT
function name:  isValidLineLength
number of ops:  8
compiled vars:  !0 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   64     1        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Cstrlen'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        FETCH_OBJ_R                                      ~2      'validLineLength'
          5        IS_SMALLER                                       ~3      $1, ~2
          6      > RETURN                                                   ~3
   65     7*     > RETURN                                                   null

End of function isvalidlinelength

Function validator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/HGChT
function name:  Validator
number of ops:  10
compiled vars:  !0 = $definitions, !1 = $definition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   ASSIGN_OBJ                                               'validLineLength'
          1        OP_DATA                                                  0
   69     2      > FE_RESET_R                                       $3      !0, ->8
          3    > > FE_FETCH_R                                               $3, !1, ->8
   70     4    >   FETCH_OBJ_R                                      ~5      !1, 'length'
          5        ASSIGN_OBJ_OP                                 1          'validLineLength'
          6        OP_DATA                                                  ~5
   69     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $3
   72     9      > RETURN                                                   null

End of function validator

End of class FlatFileParser\Validator.

Class FlatFileParser\Parser:
Function convertlinetobusiness:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/HGChT
function name:  convertLineToBusiness
number of ops:  25
compiled vars:  !0 = $line, !1 = $start, !2 = $parms, !3 = $definitions, !4 = $definition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
   77     1        ASSIGN                                                   !1, 0
   78     2        ASSIGN                                                   !2, <array>
   79     3      > FE_RESET_R                                       $7      !3, ->19
          4    > > FE_FETCH_R                                               $7, !4, ->19
   80     5    >   INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Carray_push'
          6        SEND_VAR_EX                                              !2
          7        INIT_NS_FCALL_BY_NAME                                    'FlatFileParser%5Csubstr'
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !1
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $8      !4, 'length'
         12        SEND_FUNC_ARG                                            $8
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR_NO_REF_EX                                       $9
         15        DO_FCALL                                      0          
   81    16        FETCH_OBJ_R                                      ~11     !4, 'length'
         17        ASSIGN_OP                                     1          !1, ~11
   79    18      > JMP                                                      ->4
         19    >   FE_FREE                                                  $7
   83    20        NEW                                              $13     'FlatFileParser%5CBusiness'
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0          
         23      > RETURN                                                   $13
   84    24*     > RETURN                                                   null

End of function convertlinetobusiness

End of class FlatFileParser\Parser.

Class FlatFileParser\Business:
Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGChT
function name:  __get
number of ops:  10
compiled vars:  !0 = $attribute
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   RECV                                             !0      
  106     1        CONCAT                                           ~1      '_', !0
          2        ISSET_ISEMPTY_PROP_OBJ                                   ~1
          3      > JMPZ                                                     ~2, ->8
  107     4    >   CONCAT                                           ~3      '_', !0
          5        FETCH_OBJ_R                                      ~4      ~3
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->9
  110     8    > > RETURN                                                   <false>
  112     9*     > RETURN                                                   null

End of function __get

Function business:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGChT
function name:  Business
number of ops:  20
compiled vars:  !0 = $parms
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   RECV                                             !0      
  116     1        FETCH_DIM_R                                      ~2      !0, 1
          2        ASSIGN_OBJ                                               'serialNumber'
          3        OP_DATA                                                  ~2
  117     4        FETCH_DIM_R                                      ~4      !0, 2
          5        ASSIGN_OBJ                                               'language'
          6        OP_DATA                                                  ~4
  118     7        FETCH_DIM_R                                      ~6      !0, 3
          8        ASSIGN_OBJ                                               'businessName'
          9        OP_DATA                                                  ~6
  119    10        FETCH_DIM_R                                      ~8      !0, 4
         11        ASSIGN_OBJ                                               'businessCode'
         12        OP_DATA                                                  ~8
  120    13        FETCH_DIM_R                                      ~10     !0, 5
         14        ASSIGN_OBJ                                               'authorizationCode'
         15        OP_DATA                                                  ~10
  121    16        FETCH_DIM_R                                      ~12     !0, 6
         17        ASSIGN_OBJ                                               'timestamp'
         18        OP_DATA                                                  ~12
  122    19      > RETURN                                                   null

End of function business

End of class FlatFileParser\Business.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.91 ms | 1419 KiB | 29 Q