3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class FyndiqCSVFeedWriter generates CSV export feed */ class FyndiqCSVFeedWriter { /** * @var array export column names */ private $header = array(); /** * @var array products for export */ private $products = array(); /** * @var array fields upon which `addslashes` will be applied */ private $slashFields = array( 'article-name', 'product-brand', 'product-title', 'product-description', ); /** * Apply field transformations * * @param array $product * @return array mixed */ private function processProduct($product) { foreach($this->slashFields as $field) { if (!empty($product[$field])) { $product[$field] = addslashes($product[$field]); } } return $product; } /** * Add product to the feed * * @param $product * @return bool */ public function addProduct($product) { if ($this->isValidProduct($product)) { $this->header = array_unique(array_merge($this->header, array_keys($product))); $this->products[] = $this->processProduct($product); return true; } return false; } /** * Flush the feed data to the stream * * @return bool */ public function write() { // Write header if (fputcsv($this->stream, $this->header) === false) { return false; } // Write data foreach ($this->products as $product) { $finalProduct = array(); foreach ($this->header as $column) { $finalProduct[] = isset($product[$column]) ? $product[$column] : ''; } if (fputcsv($this->stream, $finalProduct) === false) { return false; } } unset($this->header); unset($this->products); return true; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rNqZ7
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E > > RETURN                                                   1

Class FyndiqCSVFeedWriter:
Function processproduct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/rNqZ7
function name:  processProduct
number of ops:  17
compiled vars:  !0 = $product, !1 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        FETCH_OBJ_R                                      ~2      'slashFields'
          2      > FE_RESET_R                                       $3      ~2, ->14
          3    > > FE_FETCH_R                                               $3, !1, ->14
   37     4    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~4      !0, !1
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->13
   38     7    >   INIT_FCALL                                               'addslashes'
          8        FETCH_DIM_R                                      ~7      !0, !1
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11        ASSIGN_DIM                                               !0, !1
         12        OP_DATA                                                  $8
   36    13    > > JMP                                                      ->3
         14    >   FE_FREE                                                  $3
   41    15      > RETURN                                                   !0
   42    16*     > RETURN                                                   null

End of function processproduct

Function addproduct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rNqZ7
function name:  addProduct
number of ops:  27
compiled vars:  !0 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        INIT_METHOD_CALL                                         'isValidProduct'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > JMPZ                                                     $1, ->25
   52     5    >   INIT_FCALL                                               'array_unique'
          6        INIT_FCALL                                               'array_merge'
          7        FETCH_OBJ_R                                      ~3      'header'
          8        SEND_VAL                                                 ~3
          9        INIT_FCALL                                               'array_keys'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $4      
         12        SEND_VAR                                                 $4
         13        DO_ICALL                                         $5      
         14        SEND_VAR                                                 $5
         15        DO_ICALL                                         $6      
         16        ASSIGN_OBJ                                               'header'
         17        OP_DATA                                                  $6
   53    18        INIT_METHOD_CALL                                         'processProduct'
         19        SEND_VAR                                                 !0
         20        DO_FCALL                                      0  $9      
         21        FETCH_OBJ_W                                      $7      'products'
         22        ASSIGN_DIM                                               $7
         23        OP_DATA                                                  $9
   54    24      > RETURN                                                   <true>
   56    25    > > RETURN                                                   <false>
   57    26*     > RETURN                                                   null

End of function addproduct

Function write:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 36
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 36
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 25
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/rNqZ7
function name:  write
number of ops:  41
compiled vars:  !0 = $product, !1 = $finalProduct, !2 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_FCALL                                               'fputcsv'
          1        FETCH_OBJ_R                                      ~3      'stream'
          2        SEND_VAL                                                 ~3
          3        FETCH_OBJ_R                                      ~4      'header'
          4        SEND_VAL                                                 ~4
          5        DO_ICALL                                         $5      
          6        TYPE_CHECK                                    4          $5
          7      > JMPZ                                                     ~6, ->9
   67     8    > > RETURN                                                   <false>
   71     9    >   FETCH_OBJ_R                                      ~7      'products'
         10      > FE_RESET_R                                       $8      ~7, ->36
         11    > > FE_FETCH_R                                               $8, !0, ->36
   72    12    >   ASSIGN                                                   !1, <array>
   73    13        FETCH_OBJ_R                                      ~10     'header'
         14      > FE_RESET_R                                       $11     ~10, ->25
         15    > > FE_FETCH_R                                               $11, !2, ->25
   74    16    >   ISSET_ISEMPTY_DIM_OBJ                         0          !0, !2
         17      > JMPZ                                                     ~13, ->21
         18    >   FETCH_DIM_R                                      ~14     !0, !2
         19        QM_ASSIGN                                        ~15     ~14
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~15     ''
         22    >   ASSIGN_DIM                                               !1
         23        OP_DATA                                                  ~15
   73    24      > JMP                                                      ->15
         25    >   FE_FREE                                                  $11
   76    26        INIT_FCALL                                               'fputcsv'
         27        FETCH_OBJ_R                                      ~16     'stream'
         28        SEND_VAL                                                 ~16
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $17     
         31        TYPE_CHECK                                    4          $17
         32      > JMPZ                                                     ~18, ->35
   77    33    >   FE_FREE                                                  $8
         34      > RETURN                                                   <false>
   71    35    > > JMP                                                      ->11
         36    >   FE_FREE                                                  $8
   80    37        UNSET_OBJ                                                'header'
   81    38        UNSET_OBJ                                                'products'
   82    39      > RETURN                                                   <true>
   83    40*     > RETURN                                                   null

End of function write

End of class FyndiqCSVFeedWriter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.99 ms | 1404 KiB | 23 Q