GitHub
Tests: 12 • Commercial: 2 • Pet projects: 4 • Legacy: 4
Total: 22

.NET Framework

Test
2021

Project Request

ASP.NET MVC • C# • SQL Server
Idea of the project: if someone wants to order a project development, here you can send an application.
Test
2020

ProjectC

ASP.NET MVC • C# • JSON • jQuery
JSON data processing.
Test
2020

Vehicle Maintenance

ASP.NET MVC • VB.NET • JSON
Idea of the project: if someone wants to order a project development, here you can send an application.
Test
2019

Movie Navigator

ASP.NET MVC • VB.NET
Request information about movie from IMDB.
Test
2018

Customers Exchange

ASP.NET MVC • C# • SQL Server
Automated teller machine emulation.
Test
2016

ATM

ASP.NET MVC • C#
Automated teller machine emulation.

.NET Core

Pet project
2022

Mail Daemon

.NET 9 • Console • JSON
Utility to send mails with customizable settings.

Custom

Code
2024

Buns of code

.NET Framework • C# • JavaScript
Code snippets from my projects, ready to use; tiny tests; code examples.

PHP

Test
2024

Mediabox

PHP 8 • Laravel 11 • Vue.js • Composer • SQLite
Test project for media files management.
Test
2020

Loan Castle

PHP • MariaDB
Jums jāizstrādā kāda lielāk projekta prototips. Izstrādājot prototipu, paturiet prātā, ka projektam attīstoties, šo prototipu varētu vajadzēt pilnveidot.
Test
2020

Content Management

PHP • MySQL • AJAX
Создать простой сайт, где будет страница с формой для авторизации и страница для авторизованного пользователя.
Test
2019

Laravel

PHP • Laravel • Vue.js • Composer • SQLite
Izveidot aplikāciju, kura ik pēc noteikta intervāla (60 sekundes) veic ierakstu datubāzē izmantojot Laravel freimworka iebūvēto funkcionalitāti.
Test
2019

Phone Check

PHP • JavaScript • JSON • Docker
Implement application to detect country by phone number.

Frontend

Test
2021

Forex Wall

npm • React
For this exercise, what we need is a simple live wall for tracking currencies.

Business projects

Commercial
2008

Certification Center

.NET Framework 4.8 • ASP.NET Web Forms • C# • LINQ • SQL Server • ADO.NET • Dapper • JavaScript • jQuery • Git
Transport registration and certification services in Latvia, Customer Relationship Management.
Commercial
2000

Amerikas Auto

.NET Framework 4.8 • ASP.NET Web Forms • C# • LINQ • SQL Server • ADO.NET • Entity Framework • JavaScript • jQuery • Git
Car service and spare parts for all USA and European car models, Customer Relationship Management.

Pet projects

Pet project
2023

Geolocation Assistant

.NET 8 • ASP.NET Core • C# • Web API • JSON • Git
Website for determining geolocation by IP or geotagged photo.
Pet project
2008

Web Dynamics

.NET Framework 4.8 • ASP.NET Web Forms • C# • LINQ • Web API • JSON • SQL Server • Dapper • JavaScript • jQuery • SVG • Git
Software development blog. Articles, books, videos, content management.
Pet project
2000

Blackball

.NET Framework 4.8 • ASP.NET Web Forms • C# • LINQ • Web API • JSON • XML • SQL Server • Dapper • JavaScript • jQuery • SVG • Git
My entertainment portal created from scratch.

Good old times

Legacy
2000

DOS Clock

Turbo Pascal • Assembler
Digital clock.
Legacy
2000

BrainOut

Turbo Pascal • Assembler
Tank battle game.
Legacy
1999

Airport Administrator

Turbo Pascal
Курсовая работа в институте.
Legacy
1998

Atomizer

Turbo Pascal • Assembler
Atomizer, aka «Studio2D». Graphic raster editor. AGI is my own «Atomizer Generated Image» file format.

Laravel

2019 Test

Izveidot aplikāciju, kura ik pēc noteikta intervāla (60 sekundes) veic ierakstu datubāzē izmantojot Laravel freimworka iebūvēto funkcionalitāti.

PHP Laravel Vue.js Composer SQLite
Information
Source code
  app
  Http
  Auth
  css
  js
  js
  lang
  en
  sass
  app
  data
  logs
  Unit
  src
  src
  lib
  docs
  en
  src
  docs
  en
  lib
  src
  Cron
  Cron
  src
  filp
  src
  css
  js
  Util
  src
  ORM
  Spot
  test
  Core
  Text
  Type
  Xml
  Core
  Text
  Type
  Xml
  html
  src
  src
  src
  Auth
  make
  auth
  Bus
  Auth
  Bus
  Http
  Mail
  View
  Auth
  Bus
  Http
  Http
  Json
  Log
  Mail
  html
  text
  Jobs
  View
  src
  src
  Util
  docs
  Pass
  Pass
  Pass
  doc
  src
  Curl
  doc
  f001
  f002
  f003
  f004
  f005
  f006
  f007
  f008
  src
  Date
  Spl
  src
  Lang
  List
  doc
  lib
  Node
  Expr
  Cast
  Name
  Stmt
  test
  code
  expr
  uvs
  stmt
  loop
  expr
  stmt
  Node
  Stmt
  src
  opis
  src
  dist
  lib
  src
  xml
  xml
  src
  Unit
  src
  src
  Tags
  src
  src
  src
  Call
  Node
  Call
  Util
  src
  Node
  Html
  css
  js
  Xml
  HTML
  XML
  src
  src
  src
  src
  src
  Stub
  Hook
  Util
  Log
  PHP
  cli
  1149
  1216
  1265
  1330
  1335
  1337
  1348
  1351
  1374
  1437
  1468
  1471
  1472
  1570
  2085
  2137
  2145
  2158
  2366
  2380
  2382
  2435
  244
  2448
  2724
  2725
  2731
  2811
  2830
  2972
  3093
  3107
  3156
  322
  3364
  3379
  3380
  3396
  433
  445
  498
  503
  581
  74
  765
  797
  873
  Trac
  1021
  523
  578
  684
  783
  fail
  unit
  Util
  PHP
  psr
  src
  log
  Psr
  Log
  Test
  src
  psy
  src
  Sudo
  Util
  test
  Sudo
  Util
  box
  uuid
  src
  Time
  Node
  Time
  src
  src
  diff
  src
  out
  src
  src
  src
  src
  src
  src
  src
  src
  doc
  lib
  Mime
  Pop
  Auth
  Mime
  bug
  unit
  Mime
  Auth
  dkim
  Node
  Node
  psr4
  phpt
  .dot
  b
  a
  A
  B
  C
  copy
  A
  B
  C
  one
  b
  .dot
  a
  dir
  File
  Test
  File
  test
  Test
  Log
  Log
  mime
  Part
  test
  Part
  glob
  Test
  data
  dat
  res
  Util
  Util
  Test
  css
  js
  Test
  Test
  src
  src
  Css
  Rule
  src
  src
  .env
  null
Root / vendor / nikic / php-parser / lib / PhpParser / PrettyPrinter / Standard.php
<?php declare(strict_types=1); namespace PhpParser\PrettyPrinter; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\Cast; use PhpParser\Node\Name; use PhpParser\Node\Scalar; use PhpParser\Node\Scalar\MagicConst; use PhpParser\Node\Stmt; use PhpParser\PrettyPrinterAbstract; class Standard extends PrettyPrinterAbstract { // Special nodes protected function pParam(Node\Param $node) { return ($node->type ? $this->p($node->type) . ' ' : '') . ($node->byRef ? '&' : '') . ($node->variadic ? '...' : '') . $this->p($node->var) . ($node->default ? ' = ' . $this->p($node->default) : ''); } protected function pArg(Node\Arg $node) { return ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); } protected function pConst(Node\Const_ $node) { return $node->name . ' = ' . $this->p($node->value); } protected function pNullableType(Node\NullableType $node) { return '?' . $this->p($node->type); } protected function pIdentifier(Node\Identifier $node) { return $node->name; } protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node) { return '$' . $node->name; } // Names protected function pName(Name $node) { return implode('\\', $node->parts); } protected function pName_FullyQualified(Name\FullyQualified $node) { return '\\' . implode('\\', $node->parts); } protected function pName_Relative(Name\Relative $node) { return 'namespace\\' . implode('\\', $node->parts); } // Magic Constants protected function pScalar_MagicConst_Class(MagicConst\Class_ $node) { return '__CLASS__'; } protected function pScalar_MagicConst_Dir(MagicConst\Dir $node) { return '__DIR__'; } protected function pScalar_MagicConst_File(MagicConst\File $node) { return '__FILE__'; } protected function pScalar_MagicConst_Function(MagicConst\Function_ $node) { return '__FUNCTION__'; } protected function pScalar_MagicConst_Line(MagicConst\Line $node) { return '__LINE__'; } protected function pScalar_MagicConst_Method(MagicConst\Method $node) { return '__METHOD__'; } protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) { return '__NAMESPACE__'; } protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) { return '__TRAIT__'; } // Scalars protected function pScalar_String(Scalar\String_ $node) { $kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED); switch ($kind) { case Scalar\String_::KIND_NOWDOC: $label = $node->getAttribute('docLabel'); if ($label && !$this->containsEndLabel($node->value, $label)) { if ($node->value === '') { return "<<<'$label'\n$label" . $this->docStringEndToken; } return "<<<'$label'\n$node->value\n$label" . $this->docStringEndToken; } /* break missing intentionally */ case Scalar\String_::KIND_SINGLE_QUOTED: return $this->pSingleQuotedString($node->value); case Scalar\String_::KIND_HEREDOC: $label = $node->getAttribute('docLabel'); if ($label && !$this->containsEndLabel($node->value, $label)) { if ($node->value === '') { return "<<<$label\n$label" . $this->docStringEndToken; } $escaped = $this->escapeString($node->value, null); return "<<<$label\n" . $escaped . "\n$label" . $this->docStringEndToken; } /* break missing intentionally */ case Scalar\String_::KIND_DOUBLE_QUOTED: return '"' . $this->escapeString($node->value, '"') . '"'; } throw new \Exception('Invalid string kind'); } protected function pScalar_Encapsed(Scalar\Encapsed $node) { if ($node->getAttribute('kind') === Scalar\String_::KIND_HEREDOC) { $label = $node->getAttribute('docLabel'); if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) { if (count($node->parts) === 1 && $node->parts[0] instanceof Scalar\EncapsedStringPart && $node->parts[0]->value === '' ) { return "<<<$label\n$label" . $this->docStringEndToken; } return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label" . $this->docStringEndToken; } } return '"' . $this->pEncapsList($node->parts, '"') . '"'; } protected function pScalar_LNumber(Scalar\LNumber $node) { if ($node->value === -\PHP_INT_MAX-1) { // PHP_INT_MIN cannot be represented as a literal, // because the sign is not part of the literal return '(-' . \PHP_INT_MAX . '-1)'; } $kind = $node->getAttribute('kind', Scalar\LNumber::KIND_DEC); if (Scalar\LNumber::KIND_DEC === $kind) { return (string) $node->value; } $sign = $node->value < 0 ? '-' : ''; $str = (string) $node->value; switch ($kind) { case Scalar\LNumber::KIND_BIN: return $sign . '0b' . base_convert($str, 10, 2); case Scalar\LNumber::KIND_OCT: return $sign . '0' . base_convert($str, 10, 8); case Scalar\LNumber::KIND_HEX: return $sign . '0x' . base_convert($str, 10, 16); } throw new \Exception('Invalid number kind'); } protected function pScalar_DNumber(Scalar\DNumber $node) { if (!is_finite($node->value)) { if ($node->value === \INF) { return '\INF'; } elseif ($node->value === -\INF) { return '-\INF'; } else { return '\NAN'; } } // Try to find a short full-precision representation $stringValue = sprintf('%.16G', $node->value); if ($node->value !== (double) $stringValue) { $stringValue = sprintf('%.17G', $node->value); } // %G is locale dependent and there exists no locale-independent alternative. We don't want // mess with switching locales here, so let's assume that a comma is the only non-standard // decimal separator we may encounter... $stringValue = str_replace(',', '.', $stringValue); // ensure that number is really printed as float return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; } protected function pScalar_EncapsedStringPart(Scalar\EncapsedStringPart $node) { throw new \LogicException('Cannot directly print EncapsedStringPart'); } // Assignments protected function pExpr_Assign(Expr\Assign $node) { return $this->pInfixOp(Expr\Assign::class, $node->var, ' = ', $node->expr); } protected function pExpr_AssignRef(Expr\AssignRef $node) { return $this->pInfixOp(Expr\AssignRef::class, $node->var, ' =& ', $node->expr); } protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) { return $this->pInfixOp(AssignOp\Plus::class, $node->var, ' += ', $node->expr); } protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) { return $this->pInfixOp(AssignOp\Minus::class, $node->var, ' -= ', $node->expr); } protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) { return $this->pInfixOp(AssignOp\Mul::class, $node->var, ' *= ', $node->expr); } protected function pExpr_AssignOp_Div(AssignOp\Div $node) { return $this->pInfixOp(AssignOp\Div::class, $node->var, ' /= ', $node->expr); } protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) { return $this->pInfixOp(AssignOp\Concat::class, $node->var, ' .= ', $node->expr); } protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) { return $this->pInfixOp(AssignOp\Mod::class, $node->var, ' %= ', $node->expr); } protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) { return $this->pInfixOp(AssignOp\BitwiseAnd::class, $node->var, ' &= ', $node->expr); } protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) { return $this->pInfixOp(AssignOp\BitwiseOr::class, $node->var, ' |= ', $node->expr); } protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) { return $this->pInfixOp(AssignOp\BitwiseXor::class, $node->var, ' ^= ', $node->expr); } protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) { return $this->pInfixOp(AssignOp\ShiftLeft::class, $node->var, ' <<= ', $node->expr); } protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) { return $this->pInfixOp(AssignOp\ShiftRight::class, $node->var, ' >>= ', $node->expr); } protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) { return $this->pInfixOp(AssignOp\Pow::class, $node->var, ' **= ', $node->expr); } protected function pExpr_AssignOp_Coalesce(AssignOp\Coalesce $node) { return $this->pInfixOp(AssignOp\Coalesce::class, $node->var, ' ??= ', $node->expr); } // Binary expressions protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) { return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right); } protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) { return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right); } protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) { return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right); } protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) { return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right); } protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) { return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right); } protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) { return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right); } protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) { return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right); } protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) { return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right); } protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) { return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right); } protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) { return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right); } protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) { return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right); } protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) { return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right); } protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) { return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right); } protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) { return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right); } protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) { return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right); } protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) { return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right); } protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) { return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right); } protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) { return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right); } protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) { return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right); } protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) { return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right); } protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) { return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right); } protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) { return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right); } protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) { return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right); } protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) { return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right); } protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) { return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right); } protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) { return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right); } protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) { return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right); } protected function pExpr_Instanceof(Expr\Instanceof_ $node) { return $this->pInfixOp(Expr\Instanceof_::class, $node->expr, ' instanceof ', $node->class); } // Unary expressions protected function pExpr_BooleanNot(Expr\BooleanNot $node) { return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr); } protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) { return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr); } protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) { if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) { // Enforce -(-$expr) instead of --$expr return '-(' . $this->p($node->expr) . ')'; } return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr); } protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) { if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) { // Enforce +(+$expr) instead of ++$expr return '+(' . $this->p($node->expr) . ')'; } return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr); } protected function pExpr_PreInc(Expr\PreInc $node) { return $this->pPrefixOp(Expr\PreInc::class, '++', $node->var); } protected function pExpr_PreDec(Expr\PreDec $node) { return $this->pPrefixOp(Expr\PreDec::class, '--', $node->var); } protected function pExpr_PostInc(Expr\PostInc $node) { return $this->pPostfixOp(Expr\PostInc::class, $node->var, '++'); } protected function pExpr_PostDec(Expr\PostDec $node) { return $this->pPostfixOp(Expr\PostDec::class, $node->var, '--'); } protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) { return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr); } protected function pExpr_YieldFrom(Expr\YieldFrom $node) { return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr); } protected function pExpr_Print(Expr\Print_ $node) { return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr); } // Casts protected function pExpr_Cast_Int(Cast\Int_ $node) { return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr); } protected function pExpr_Cast_Double(Cast\Double $node) { $kind = $node->getAttribute('kind', Cast\Double::KIND_DOUBLE); if ($kind === Cast\Double::KIND_DOUBLE) { $cast = '(double)'; } elseif ($kind === Cast\Double::KIND_FLOAT) { $cast = '(float)'; } elseif ($kind === Cast\Double::KIND_REAL) { $cast = '(real)'; } return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr); } protected function pExpr_Cast_String(Cast\String_ $node) { return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr); } protected function pExpr_Cast_Array(Cast\Array_ $node) { return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr); } protected function pExpr_Cast_Object(Cast\Object_ $node) { return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr); } protected function pExpr_Cast_Bool(Cast\Bool_ $node) { return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr); } protected function pExpr_Cast_Unset(Cast\Unset_ $node) { return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr); } // Function calls and similar constructs protected function pExpr_FuncCall(Expr\FuncCall $node) { return $this->pCallLhs($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_MethodCall(Expr\MethodCall $node) { return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_StaticCall(Expr\StaticCall $node) { return $this->pDereferenceLhs($node->class) . '::' . ($node->name instanceof Expr ? ($node->name instanceof Expr\Variable ? $this->p($node->name) : '{' . $this->p($node->name) . '}') : $node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_Empty(Expr\Empty_ $node) { return 'empty(' . $this->p($node->expr) . ')'; } protected function pExpr_Isset(Expr\Isset_ $node) { return 'isset(' . $this->pCommaSeparated($node->vars) . ')'; } protected function pExpr_Eval(Expr\Eval_ $node) { return 'eval(' . $this->p($node->expr) . ')'; } protected function pExpr_Include(Expr\Include_ $node) { static $map = [ Expr\Include_::TYPE_INCLUDE => 'include', Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', Expr\Include_::TYPE_REQUIRE => 'require', Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', ]; return $map[$node->type] . ' ' . $this->p($node->expr); } protected function pExpr_List(Expr\List_ $node) { return 'list(' . $this->pCommaSeparated($node->items) . ')'; } // Other protected function pExpr_Error(Expr\Error $node) { throw new \LogicException('Cannot pretty-print AST with Error nodes'); } protected function pExpr_Variable(Expr\Variable $node) { if ($node->name instanceof Expr) { return '${' . $this->p($node->name) . '}'; } else { return '$' . $node->name; } } protected function pExpr_Array(Expr\Array_ $node) { $syntax = $node->getAttribute('kind', $this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG); if ($syntax === Expr\Array_::KIND_SHORT) { return '[' . $this->pMaybeMultiline($node->items, true) . ']'; } else { return 'array(' . $this->pMaybeMultiline($node->items, true) . ')'; } } protected function pExpr_ArrayItem(Expr\ArrayItem $node) { return (null !== $node->key ? $this->p($node->key) . ' => ' : '') . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); } protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) { return $this->pDereferenceLhs($node->var) . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']'; } protected function pExpr_ConstFetch(Expr\ConstFetch $node) { return $this->p($node->name); } protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) { return $this->p($node->class) . '::' . $this->p($node->name); } protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) { return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name); } protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) { return $this->pDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name); } protected function pExpr_ShellExec(Expr\ShellExec $node) { return '`' . $this->pEncapsList($node->parts, '`') . '`'; } protected function pExpr_Closure(Expr\Closure $node) { return ($node->static ? 'static ' : '') . 'function ' . ($node->byRef ? '&' : '') . '(' . $this->pCommaSeparated($node->params) . ')' . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '') . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pExpr_ArrowFunction(Expr\ArrowFunction $node) { return ($node->static ? 'static ' : '') . 'fn' . ($node->byRef ? '&' : '') . '(' . $this->pCommaSeparated($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . ' => ' . $this->p($node->expr); } protected function pExpr_ClosureUse(Expr\ClosureUse $node) { return ($node->byRef ? '&' : '') . $this->p($node->var); } protected function pExpr_New(Expr\New_ $node) { if ($node->class instanceof Stmt\Class_) { $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : ''; return 'new ' . $this->pClassCommon($node->class, $args); } return 'new ' . $this->p($node->class) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_Clone(Expr\Clone_ $node) { return 'clone ' . $this->p($node->expr); } protected function pExpr_Ternary(Expr\Ternary $node) { // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. // this is okay because the part between ? and : never needs parentheses. return $this->pInfixOp(Expr\Ternary::class, $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else ); } protected function pExpr_Exit(Expr\Exit_ $node) { $kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE); return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die') . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : ''); } protected function pExpr_Yield(Expr\Yield_ $node) { if ($node->value === null) { return 'yield'; } else { // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary return '(yield ' . ($node->key !== null ? $this->p($node->key) . ' => ' : '') . $this->p($node->value) . ')'; } } // Declarations protected function pStmt_Namespace(Stmt\Namespace_ $node) { if ($this->canUseSemicolonNamespaces) { return 'namespace ' . $this->p($node->name) . ';' . $this->nl . $this->pStmts($node->stmts, false); } else { return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; } } protected function pStmt_Use(Stmt\Use_ $node) { return 'use ' . $this->pUseType($node->type) . $this->pCommaSeparated($node->uses) . ';'; } protected function pStmt_GroupUse(Stmt\GroupUse $node) { return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix) . '\{' . $this->pCommaSeparated($node->uses) . '};'; } protected function pStmt_UseUse(Stmt\UseUse $node) { return $this->pUseType($node->type) . $this->p($node->name) . (null !== $node->alias ? ' as ' . $node->alias : ''); } protected function pUseType($type) { return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); } protected function pStmt_Interface(Stmt\Interface_ $node) { return 'interface ' . $node->name . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Class(Stmt\Class_ $node) { return $this->pClassCommon($node, ' ' . $node->name); } protected function pStmt_Trait(Stmt\Trait_ $node) { return 'trait ' . $node->name . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_TraitUse(Stmt\TraitUse $node) { return 'use ' . $this->pCommaSeparated($node->traits) . (empty($node->adaptations) ? ';' : ' {' . $this->pStmts($node->adaptations) . $this->nl . '}'); } protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { return $this->p($node->trait) . '::' . $node->method . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; } protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) { return (null !== $node->trait ? $this->p($node->trait) . '::' : '') . $node->method . ' as' . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') . (null !== $node->newName ? ' ' . $node->newName : '') . ';'; } protected function pStmt_Property(Stmt\Property $node) { return (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags)) . ($node->type ? $this->p($node->type) . ' ' : '') . $this->pCommaSeparated($node->props) . ';'; } protected function pStmt_PropertyProperty(Stmt\PropertyProperty $node) { return '$' . $node->name . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); } protected function pStmt_ClassMethod(Stmt\ClassMethod $node) { return $this->pModifiers($node->flags) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(' . $this->pCommaSeparated($node->params) . ')' . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') . (null !== $node->stmts ? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); } protected function pStmt_ClassConst(Stmt\ClassConst $node) { return $this->pModifiers($node->flags) . 'const ' . $this->pCommaSeparated($node->consts) . ';'; } protected function pStmt_Function(Stmt\Function_ $node) { return 'function ' . ($node->byRef ? '&' : '') . $node->name . '(' . $this->pCommaSeparated($node->params) . ')' . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Const(Stmt\Const_ $node) { return 'const ' . $this->pCommaSeparated($node->consts) . ';'; } protected function pStmt_Declare(Stmt\Declare_ $node) { return 'declare (' . $this->pCommaSeparated($node->declares) . ')' . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); } protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { return $node->key . '=' . $this->p($node->value); } // Control flow protected function pStmt_If(Stmt\If_ $node) { return 'if (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}' . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '') . (null !== $node->else ? ' ' . $this->p($node->else) : ''); } protected function pStmt_ElseIf(Stmt\ElseIf_ $node) { return 'elseif (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Else(Stmt\Else_ $node) { return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_For(Stmt\For_ $node) { return 'for (' . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') . $this->pCommaSeparated($node->loop) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Foreach(Stmt\Foreach_ $node) { return 'foreach (' . $this->p($node->expr) . ' as ' . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_While(Stmt\While_ $node) { return 'while (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Do(Stmt\Do_ $node) { return 'do {' . $this->pStmts($node->stmts) . $this->nl . '} while (' . $this->p($node->cond) . ');'; } protected function pStmt_Switch(Stmt\Switch_ $node) { return 'switch (' . $this->p($node->cond) . ') {' . $this->pStmts($node->cases) . $this->nl . '}'; } protected function pStmt_Case(Stmt\Case_ $node) { return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' . $this->pStmts($node->stmts); } protected function pStmt_TryCatch(Stmt\TryCatch $node) { return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}' . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '') . ($node->finally !== null ? ' ' . $this->p($node->finally) : ''); } protected function pStmt_Catch(Stmt\Catch_ $node) { return 'catch (' . $this->pImplode($node->types, '|') . ' ' . $this->p($node->var) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Finally(Stmt\Finally_ $node) { return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Break(Stmt\Break_ $node) { return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; } protected function pStmt_Continue(Stmt\Continue_ $node) { return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; } protected function pStmt_Return(Stmt\Return_ $node) { return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';'; } protected function pStmt_Throw(Stmt\Throw_ $node) { return 'throw ' . $this->p($node->expr) . ';'; } protected function pStmt_Label(Stmt\Label $node) { return $node->name . ':'; } protected function pStmt_Goto(Stmt\Goto_ $node) { return 'goto ' . $node->name . ';'; } // Other protected function pStmt_Expression(Stmt\Expression $node) { return $this->p($node->expr) . ';'; } protected function pStmt_Echo(Stmt\Echo_ $node) { return 'echo ' . $this->pCommaSeparated($node->exprs) . ';'; } protected function pStmt_Static(Stmt\Static_ $node) { return 'static ' . $this->pCommaSeparated($node->vars) . ';'; } protected function pStmt_Global(Stmt\Global_ $node) { return 'global ' . $this->pCommaSeparated($node->vars) . ';'; } protected function pStmt_StaticVar(Stmt\StaticVar $node) { return $this->p($node->var) . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); } protected function pStmt_Unset(Stmt\Unset_ $node) { return 'unset(' . $this->pCommaSeparated($node->vars) . ');'; } protected function pStmt_InlineHTML(Stmt\InlineHTML $node) { $newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : ''; return '?>' . $newline . $node->value . '<?php '; } protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) { return '__halt_compiler();' . $node->remaining; } protected function pStmt_Nop(Stmt\Nop $node) { return ''; } // Helpers protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { return $this->pModifiers($node->flags) . 'class' . $afterClassToken . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '') . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pObjectProperty($node) { if ($node instanceof Expr) { return '{' . $this->p($node) . '}'; } else { return $node; } } protected function pEncapsList(array $encapsList, $quote) { $return = ''; foreach ($encapsList as $element) { if ($element instanceof Scalar\EncapsedStringPart) { $return .= $this->escapeString($element->value, $quote); } else { $return .= '{' . $this->p($element) . '}'; } } return $return; } protected function pSingleQuotedString(string $string) { return '\'' . addcslashes($string, '\'\\') . '\''; } protected function escapeString($string, $quote) { if (null === $quote) { // For doc strings, don't escape newlines $escaped = addcslashes($string, "\t\f\v$\\"); } else { $escaped = addcslashes($string, "\n\r\t\f\v$" . $quote . "\\"); } // Escape other control characters return preg_replace_callback('/([\0-\10\16-\37])(?=([0-7]?))/', function ($matches) { $oct = decoct(ord($matches[1])); if ($matches[2] !== '') { // If there is a trailing digit, use the full three character form return '\\' . str_pad($oct, 3, '0', \STR_PAD_LEFT); } return '\\' . $oct; }, $escaped); } protected function containsEndLabel($string, $label, $atStart = true, $atEnd = true) { $start = $atStart ? '(?:^|[\r\n])' : '[\r\n]'; $end = $atEnd ? '(?:$|[;\r\n])' : '[;\r\n]'; return false !== strpos($string, $label) && preg_match('/' . $start . $label . $end . '/', $string); } protected function encapsedContainsEndLabel(array $parts, $label) { foreach ($parts as $i => $part) { $atStart = $i === 0; $atEnd = $i === count($parts) - 1; if ($part instanceof Scalar\EncapsedStringPart && $this->containsEndLabel($part->value, $label, $atStart, $atEnd) ) { return true; } } return false; } protected function pDereferenceLhs(Node $node) { if (!$this->dereferenceLhsRequiresParens($node)) { return $this->p($node); } else { return '(' . $this->p($node) . ')'; } } protected function pCallLhs(Node $node) { if (!$this->callLhsRequiresParens($node)) { return $this->p($node); } else { return '(' . $this->p($node) . ')'; } } /** * @param Node[] $nodes * @return bool */ private function hasNodeWithComments(array $nodes) { foreach ($nodes as $node) { if ($node && $node->getComments()) { return true; } } return false; } private function pMaybeMultiline(array $nodes, $trailingComma = false) { if (!$this->hasNodeWithComments($nodes)) { return $this->pCommaSeparated($nodes); } else { return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl; } } }