repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
mossadal/math-parser
src/MathParser/Extensions/Complex.php
Complex.artanh
public static function artanh($z) { if (!($z instanceof Complex)) $z = static::parse($z); return static::div(static::log(static::div(static::add(1,$z), static::sub(1,$z))),2); }
php
public static function artanh($z) { if (!($z instanceof Complex)) $z = static::parse($z); return static::div(static::log(static::div(static::add(1,$z), static::sub(1,$z))),2); }
[ "public", "static", "function", "artanh", "(", "$", "z", ")", "{", "if", "(", "!", "(", "$", "z", "instanceof", "Complex", ")", ")", "$", "z", "=", "static", "::", "parse", "(", "$", "z", ")", ";", "return", "static", "::", "div", "(", "static", ...
complex inverse hyperbolic tangent function Complex::artanh($z) computes and returns the principal branch of artanh($z) @param mixed $z (Complex, or parsable to Complex) @retval Complex
[ "complex", "inverse", "hyperbolic", "tangent", "function" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Complex.php#L630-L634
mossadal/math-parser
src/MathParser/Extensions/Complex.php
Complex.sqrt
public static function sqrt($z) { if (!($z instanceof Complex)) $z = static::parse($z); $r = sqrt($z->abs()); $theta = $z->arg()/2; return new Complex($r*cos($theta), $r*sin($theta)); }
php
public static function sqrt($z) { if (!($z instanceof Complex)) $z = static::parse($z); $r = sqrt($z->abs()); $theta = $z->arg()/2; return new Complex($r*cos($theta), $r*sin($theta)); }
[ "public", "static", "function", "sqrt", "(", "$", "z", ")", "{", "if", "(", "!", "(", "$", "z", "instanceof", "Complex", ")", ")", "$", "z", "=", "static", "::", "parse", "(", "$", "z", ")", ";", "$", "r", "=", "sqrt", "(", "$", "z", "->", ...
complex square root function Complex::sqrt($z) computes and returns the principal branch of sqrt($z) @param mixed $z (Complex, or parsable to Complex) @retval Complex
[ "complex", "square", "root", "function" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Complex.php#L645-L653
mossadal/math-parser
src/MathParser/Interpreting/ComplexEvaluator.php
ComplexEvaluator.setVariables
public function setVariables($variables) { $this->variables = []; foreach ($variables as $var => $value) { $this->variables[$var] = Complex::parse($value); } }
php
public function setVariables($variables) { $this->variables = []; foreach ($variables as $var => $value) { $this->variables[$var] = Complex::parse($value); } }
[ "public", "function", "setVariables", "(", "$", "variables", ")", "{", "$", "this", "->", "variables", "=", "[", "]", ";", "foreach", "(", "$", "variables", "as", "$", "var", "=>", "$", "value", ")", "{", "$", "this", "->", "variables", "[", "$", "...
Update the variables used for evaluating @retval void @param array $variables Key/value pair holding current variable values
[ "Update", "the", "variables", "used", "for", "evaluating" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/ComplexEvaluator.php#L75-L81
mossadal/math-parser
src/MathParser/Interpreting/ComplexEvaluator.php
ComplexEvaluator.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $a = $node->getLeft()->accept($this); if ($node->getRight()) { $b = $node->getRight()->accept($this); } else { $b = null; } // Perform the right op...
php
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $a = $node->getLeft()->accept($this); if ($node->getRight()) { $b = $node->getRight()->accept($this); } else { $b = null; } // Perform the right op...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "operator", "=", "$", "node", "->", "getOperator", "(", ")", ";", "$", "a", "=", "$", "node", "->", "getLeft", "(", ")", "->", "accept", "(", "$", "this", ...
Evaluate an ExpressionNode Computes the value of an ExpressionNode `x op y` where `op` is one of `+`, `-`, `*`, `/` or `^` `+`, `-`, `*`, `/` or `^` @retval float @param ExpressionNode $node AST to be evaluated @throws UnknownOperatorException if the operator is something other than
[ "Evaluate", "an", "ExpressionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/ComplexEvaluator.php#L94-L126
mossadal/math-parser
src/MathParser/Interpreting/ComplexEvaluator.php
ComplexEvaluator.visitVariableNode
public function visitVariableNode(VariableNode $node) { $name = $node->getName(); if (array_key_exists($name, $this->variables)) { return $this->variables[$name]; } throw new UnknownVariableException($name); }
php
public function visitVariableNode(VariableNode $node) { $name = $node->getName(); if (array_key_exists($name, $this->variables)) { return $this->variables[$name]; } throw new UnknownVariableException($name); }
[ "public", "function", "visitVariableNode", "(", "VariableNode", "$", "node", ")", "{", "$", "name", "=", "$", "node", "->", "getName", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "variables", ")", ")", "{", ...
Evaluate a VariableNode Returns the current value of a VariableNode, as defined either by the constructor or set using the `Evaluator::setVariables()` method. VariableNode is *not* set. @retval float @see Evaluator::setVariables() to define the variables @param VariableNode $node AST to be evaluated @th...
[ "Evaluate", "a", "VariableNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/ComplexEvaluator.php#L164-L173
mossadal/math-parser
src/MathParser/Interpreting/ComplexEvaluator.php
ComplexEvaluator.visitFunctionNode
public function visitFunctionNode(FunctionNode $node) { $z = $node->getOperand()->accept($this); $a = $z->r(); $b = $z->i(); switch ($node->getName()) { // Trigonometric functions case 'sin': return Complex::sin($z); case 'cos': ...
php
public function visitFunctionNode(FunctionNode $node) { $z = $node->getOperand()->accept($this); $a = $z->r(); $b = $z->i(); switch ($node->getName()) { // Trigonometric functions case 'sin': return Complex::sin($z); case 'cos': ...
[ "public", "function", "visitFunctionNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "z", "=", "$", "node", "->", "getOperand", "(", ")", "->", "accept", "(", "$", "this", ")", ";", "$", "a", "=", "$", "z", "->", "r", "(", ")", ";", "$", ...
Evaluate a FunctionNode Computes the value of a FunctionNode `f(x)`, where f is an elementary function recognized by StdMathLexer and StdMathParser. FunctionNode is *not* recognized. @retval float @see \MathParser\Lexer\StdMathLexer StdMathLexer @see \MathParser\StdMathParser StdMathParser @param FunctionNode ...
[ "Evaluate", "a", "FunctionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/ComplexEvaluator.php#L189-L285
mossadal/math-parser
src/MathParser/Interpreting/ComplexEvaluator.php
ComplexEvaluator.visitConstantNode
public function visitConstantNode(ConstantNode $node) { switch ($node->getName()) { case 'pi': return new Complex(M_PI, 0); case 'e': return new Complex(M_E, 0); case 'i': return new Complex(0, 1); default: ...
php
public function visitConstantNode(ConstantNode $node) { switch ($node->getName()) { case 'pi': return new Complex(M_PI, 0); case 'e': return new Complex(M_E, 0); case 'i': return new Complex(0, 1); default: ...
[ "public", "function", "visitConstantNode", "(", "ConstantNode", "$", "node", ")", "{", "switch", "(", "$", "node", "->", "getName", "(", ")", ")", "{", "case", "'pi'", ":", "return", "new", "Complex", "(", "M_PI", ",", "0", ")", ";", "case", "'e'", "...
Evaluate a ConstantNode Returns the value of a ConstantNode recognized by StdMathLexer and StdMathParser. ConstantNode is *not* recognized. @retval float @see \MathParser\Lexer\StdMathLexer StdMathLexer @see \MathParser\StdMathParser StdMathParser @param ConstantNode $node AST to be evaluated @throws Un...
[ "Evaluate", "a", "ConstantNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/ComplexEvaluator.php#L300-L312
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/NodeFactory.php
NodeFactory.simplify
public function simplify(ExpressionNode $node) { switch($node->getOperator()) { case '+': return $this->addition($node->getLeft(), $node->getRight()); case '-': return $this->subtraction($node->getLeft(), $node->getRight()); case '*': return $this->multiplication($node->g...
php
public function simplify(ExpressionNode $node) { switch($node->getOperator()) { case '+': return $this->addition($node->getLeft(), $node->getRight()); case '-': return $this->subtraction($node->getLeft(), $node->getRight()); case '*': return $this->multiplication($node->g...
[ "public", "function", "simplify", "(", "ExpressionNode", "$", "node", ")", "{", "switch", "(", "$", "node", "->", "getOperator", "(", ")", ")", "{", "case", "'+'", ":", "return", "$", "this", "->", "addition", "(", "$", "node", "->", "getLeft", "(", ...
Simplify the given ExpressionNode, using the appropriate factory. @param ExpressionNode $node @retval Node Simplified version of the input
[ "Simplify", "the", "given", "ExpressionNode", "using", "the", "appropriate", "factory", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/NodeFactory.php#L173-L182
mossadal/math-parser
src/MathParser/Parsing/Nodes/ExpressionNode.php
ExpressionNode.lowerPrecedenceThan
public function lowerPrecedenceThan($other) { if (!($other instanceof ExpressionNode)) return false; if ($this->getPrecedence() < $other->getPrecedence()) return true; if ($this->getPrecedence() > $other->getPrecedence()) return false; if ($this->associativity == self::LEFT_ASSOC) ...
php
public function lowerPrecedenceThan($other) { if (!($other instanceof ExpressionNode)) return false; if ($this->getPrecedence() < $other->getPrecedence()) return true; if ($this->getPrecedence() > $other->getPrecedence()) return false; if ($this->associativity == self::LEFT_ASSOC) ...
[ "public", "function", "lowerPrecedenceThan", "(", "$", "other", ")", "{", "if", "(", "!", "(", "$", "other", "instanceof", "ExpressionNode", ")", ")", "return", "false", ";", "if", "(", "$", "this", "->", "getPrecedence", "(", ")", "<", "$", "other", "...
Returns true if the current Node has lower precedence than the one we compare with. In case of a tie, we also consider the associativity. (Left associative operators are lower precedence in this context.) @param Node $other Node to compare to. @retval boolean
[ "Returns", "true", "if", "the", "current", "Node", "has", "lower", "precedence", "than", "the", "one", "we", "compare", "with", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/ExpressionNode.php#L203-L214
mossadal/math-parser
src/MathParser/Parsing/Nodes/ExpressionNode.php
ExpressionNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof ExpressionNode)) { return false; } if ($this->getOperator() != $other->getOperator()) return false; $thisLeft = $this->getLeft(); $othe...
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof ExpressionNode)) { return false; } if ($this->getOperator() != $other->getOperator()) return false; $thisLeft = $this->getLeft(); $othe...
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "ExpressionNode", ")", ")", "{", "return", "false", ";", ...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/ExpressionNode.php#L227-L252
mossadal/math-parser
src/MathParser/Parsing/Nodes/SubExpressionNode.php
SubExpressionNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof SubExpressionNode)) { return false; } return $this->getValue() == $other->getValue(); }
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof SubExpressionNode)) { return false; } return $this->getValue() == $other->getValue(); }
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "SubExpressionNode", ")", ")", "{", "return", "false", ";"...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/SubExpressionNode.php#L53-L63
mossadal/math-parser
src/MathParser/Parsing/Nodes/RationalNode.php
RationalNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if ($other instanceof IntegerNode) { return $this->getDenominator() == 1 && $this->getNumerator() == $other->getValue(); } if (!($other instanceof RationalNode)) { r...
php
public function compareTo($other) { if ($other === null) { return false; } if ($other instanceof IntegerNode) { return $this->getDenominator() == 1 && $this->getNumerator() == $other->getValue(); } if (!($other instanceof RationalNode)) { r...
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "$", "other", "instanceof", "IntegerNode", ")", "{", "return", "$", "this", "->", "getDenominator"...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/RationalNode.php#L80-L93
mossadal/math-parser
src/MathParser/Parsing/Nodes/PostfixOperatorNode.php
PostfixOperatorNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof PostfixOperatorNode)) { return false; } return $this->getOperator() == $other->getOperator(); }
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof PostfixOperatorNode)) { return false; } return $this->getOperator() == $other->getOperator(); }
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "PostfixOperatorNode", ")", ")", "{", "return", "false", "...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/PostfixOperatorNode.php#L46-L56
mossadal/math-parser
src/MathParser/Extensions/Math.php
Math.gcd
public static function gcd($a, $b) { $sign = 1; if ($a < 0) $sign = -$sign; if ($b < 0) $sign = -$sign; while ($b != 0) { $m = $a % $b; $a = $b; $b = $m; } return $sign*abs($a); }
php
public static function gcd($a, $b) { $sign = 1; if ($a < 0) $sign = -$sign; if ($b < 0) $sign = -$sign; while ($b != 0) { $m = $a % $b; $a = $b; $b = $m; } return $sign*abs($a); }
[ "public", "static", "function", "gcd", "(", "$", "a", ",", "$", "b", ")", "{", "$", "sign", "=", "1", ";", "if", "(", "$", "a", "<", "0", ")", "$", "sign", "=", "-", "$", "sign", ";", "if", "(", "$", "b", "<", "0", ")", "$", "sign", "="...
Compute greates common denominator, using the Euclidean algorithm Compute and return gcd($a, $b) @param int $a @param int $b @retval int
[ "Compute", "greates", "common", "denominator", "using", "the", "Euclidean", "algorithm" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Math.php#L21-L34
mossadal/math-parser
src/MathParser/Extensions/Math.php
Math.logGamma
public static function logGamma($a) { if($a < 0) throw new \InvalidArgumentException("Log gamma calls should be >0."); if ($a >= 171) // Lanczos approximation w/ the given coefficients is accurate to 15 digits for 0 <= real(z) <= 171 return self::logStirlingApproximation($a); else return log(self::lancz...
php
public static function logGamma($a) { if($a < 0) throw new \InvalidArgumentException("Log gamma calls should be >0."); if ($a >= 171) // Lanczos approximation w/ the given coefficients is accurate to 15 digits for 0 <= real(z) <= 171 return self::logStirlingApproximation($a); else return log(self::lancz...
[ "public", "static", "function", "logGamma", "(", "$", "a", ")", "{", "if", "(", "$", "a", "<", "0", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Log gamma calls should be >0.\"", ")", ";", "if", "(", "$", "a", ">=", "171", ")", "// Lanc...
Compute log(Gamma($a)) where $a is a positive real number For large values of $a ($a > 171), use Stirling asympotic expansion, otherwise use the Lanczos approximation @param float $a @throws InvalidArgumentException if $a < 0 @retval float
[ "Compute", "log", "(", "Gamma", "(", "$a", "))", "where", "$a", "is", "a", "positive", "real", "number" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Math.php#L47-L55
mossadal/math-parser
src/MathParser/Extensions/Math.php
Math.logStirlingApproximation
private static function logStirlingApproximation($x) { $t = 0.5*log(2*pi()) - 0.5*log($x) + $x*(log($x))-$x; $x2 = $x * $x; $x3 = $x2 * $x; $x4 = $x3 * $x; $err_term = log(1 + (1.0/(12*$x)) + (1.0/(288*$x2)) - (139.0/(51840*$x3)) - (571.0/(2488320*$x4))); $res = $t + $err_term; return $res; }
php
private static function logStirlingApproximation($x) { $t = 0.5*log(2*pi()) - 0.5*log($x) + $x*(log($x))-$x; $x2 = $x * $x; $x3 = $x2 * $x; $x4 = $x3 * $x; $err_term = log(1 + (1.0/(12*$x)) + (1.0/(288*$x2)) - (139.0/(51840*$x3)) - (571.0/(2488320*$x4))); $res = $t + $err_term; return $res; }
[ "private", "static", "function", "logStirlingApproximation", "(", "$", "x", ")", "{", "$", "t", "=", "0.5", "*", "log", "(", "2", "*", "pi", "(", ")", ")", "-", "0.5", "*", "log", "(", "$", "x", ")", "+", "$", "x", "*", "(", "log", "(", "$", ...
Compute log(Gamma($x)) using Stirling asympotic expansion @param float $x @retval float
[ "Compute", "log", "(", "Gamma", "(", "$x", "))", "using", "Stirling", "asympotic", "expansion" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Math.php#L63-L75
mossadal/math-parser
src/MathParser/Extensions/Math.php
Math.Factorial
public static function Factorial($num) { if ($num < 0) throw new \InvalidArgumentException("Fatorial calls should be >0."); $rval=1; for ($i = 1; $i <= $num; $i++) $rval = $rval * $i; return $rval; }
php
public static function Factorial($num) { if ($num < 0) throw new \InvalidArgumentException("Fatorial calls should be >0."); $rval=1; for ($i = 1; $i <= $num; $i++) $rval = $rval * $i; return $rval; }
[ "public", "static", "function", "Factorial", "(", "$", "num", ")", "{", "if", "(", "$", "num", "<", "0", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Fatorial calls should be >0.\"", ")", ";", "$", "rval", "=", "1", ";", "for", "(", "$"...
Compute factorial n! for an integer $n using iteration @param int $num @retval int
[ "Compute", "factorial", "n!", "for", "an", "integer", "$n", "using", "iteration" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Math.php#L83-L90
mossadal/math-parser
src/MathParser/Extensions/Math.php
Math.SemiFactorial
public static function SemiFactorial($num) { if ($num < 0) throw new \InvalidArgumentException("Semifactorial calls should be >0."); $rval=1; while ($num >= 2) { $rval =$rval * $num; $num = $num-2; } return $rval; }
php
public static function SemiFactorial($num) { if ($num < 0) throw new \InvalidArgumentException("Semifactorial calls should be >0."); $rval=1; while ($num >= 2) { $rval =$rval * $num; $num = $num-2; } return $rval; }
[ "public", "static", "function", "SemiFactorial", "(", "$", "num", ")", "{", "if", "(", "$", "num", "<", "0", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Semifactorial calls should be >0.\"", ")", ";", "$", "rval", "=", "1", ";", "while", ...
Compute semi-factorial n!! for an integer $n using iteration @param int $num @retval int
[ "Compute", "semi", "-", "factorial", "n!!", "for", "an", "integer", "$n", "using", "iteration" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Math.php#L98-L107
mossadal/math-parser
src/MathParser/Extensions/Math.php
Math.lanczosApproximation
private static function lanczosApproximation($x) { $g = 7; $p = array(0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7); if (abs($x - floor($x)) < 1e-16) { // if ...
php
private static function lanczosApproximation($x) { $g = 7; $p = array(0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7); if (abs($x - floor($x)) < 1e-16) { // if ...
[ "private", "static", "function", "lanczosApproximation", "(", "$", "x", ")", "{", "$", "g", "=", "7", ";", "$", "p", "=", "array", "(", "0.99999999999980993", ",", "676.5203681218851", ",", "-", "1259.1392167224028", ",", "771.32342877765313", ",", "-", "176...
Compute log(Gamma($x)) using Lanczos approximation @param float $x @retval float
[ "Compute", "log", "(", "Gamma", "(", "$x", "))", "using", "Lanczos", "approximation" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Math.php#L115-L147
mossadal/math-parser
src/MathParser/Interpreting/RationalEvaluator.php
RationalEvaluator.setVariables
public function setVariables($variables) { $this->variables = []; foreach ($variables as $var => $value) { if ($value instanceof RationalNode) { $this->variables[$var] = $value; } elseif ($this->isInteger($value)) { $this->variables[$var] = new...
php
public function setVariables($variables) { $this->variables = []; foreach ($variables as $var => $value) { if ($value instanceof RationalNode) { $this->variables[$var] = $value; } elseif ($this->isInteger($value)) { $this->variables[$var] = new...
[ "public", "function", "setVariables", "(", "$", "variables", ")", "{", "$", "this", "->", "variables", "=", "[", "]", ";", "foreach", "(", "$", "variables", "as", "$", "var", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Ratio...
Update the variables used for evaluating @retval void @param array $variables Key/value pair holding current variable values
[ "Update", "the", "variables", "used", "for", "evaluating" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/RationalEvaluator.php#L109-L121
mossadal/math-parser
src/MathParser/Interpreting/RationalEvaluator.php
RationalEvaluator.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $a = $node->getLeft()->accept($this); if ($node->getRight()) { $b = $node->getRight()->accept($this); } else { $b = null; } // Perform the right op...
php
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $a = $node->getLeft()->accept($this); if ($node->getRight()) { $b = $node->getRight()->accept($this); } else { $b = null; } // Perform the right op...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "operator", "=", "$", "node", "->", "getOperator", "(", ")", ";", "$", "a", "=", "$", "node", "->", "getLeft", "(", ")", "->", "accept", "(", "$", "this", ...
Evaluate an ExpressionNode Computes the value of an ExpressionNode `x op y` where `op` is one of `+`, `-`, `*`, `/` or `^` `+`, `-`, `*`, `/` or `^` @retval float @param ExpressionNode $node AST to be evaluated @throws UnknownOperatorException if the operator is something other than
[ "Evaluate", "an", "ExpressionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/RationalEvaluator.php#L134-L180
mossadal/math-parser
src/MathParser/Interpreting/RationalEvaluator.php
RationalEvaluator.visitFunctionNode
public function visitFunctionNode(FunctionNode $node) { $inner = $node->getOperand()->accept($this); switch ($node->getName()) { // Trigonometric functions case 'sin': case 'cos': case 'tan': case 'cot': case 'arcsin': ...
php
public function visitFunctionNode(FunctionNode $node) { $inner = $node->getOperand()->accept($this); switch ($node->getName()) { // Trigonometric functions case 'sin': case 'cos': case 'tan': case 'cot': case 'arcsin': ...
[ "public", "function", "visitFunctionNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "inner", "=", "$", "node", "->", "getOperand", "(", ")", "->", "accept", "(", "$", "this", ")", ";", "switch", "(", "$", "node", "->", "getName", "(", ")", ")...
Evaluate a FunctionNode Computes the value of a FunctionNode `f(x)`, where f is an elementary function recognized by StdMathLexer and StdMathParser. FunctionNode is *not* recognized. @retval float @see \MathParser\Lexer\StdMathLexer StdMathLexer @see \MathParser\StdMathParser StdMathParser @param FunctionNode ...
[ "Evaluate", "a", "FunctionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/RationalEvaluator.php#L243-L302
mossadal/math-parser
src/MathParser/Interpreting/RationalEvaluator.php
RationalEvaluator.ifactor
public static function ifactor($n) { // max_n = 2^31-1 = 2147483647 $d = 2; $factors = []; $dmax = floor(sqrt($n)); self::$sieve = array_pad(self::$sieve, $dmax, 1); do { $r = false; while ($n % $d == 0) { if (array_key_exist...
php
public static function ifactor($n) { // max_n = 2^31-1 = 2147483647 $d = 2; $factors = []; $dmax = floor(sqrt($n)); self::$sieve = array_pad(self::$sieve, $dmax, 1); do { $r = false; while ($n % $d == 0) { if (array_key_exist...
[ "public", "static", "function", "ifactor", "(", "$", "n", ")", "{", "// max_n = 2^31-1 = 2147483647", "$", "d", "=", "2", ";", "$", "factors", "=", "[", "]", ";", "$", "dmax", "=", "floor", "(", "sqrt", "(", "$", "n", ")", ")", ";", "self", "::", ...
Integer factorization Computes an integer factorization of $n using trial division and a cached sieve of computed primes @param type var Description
[ "Integer", "factorization" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/RationalEvaluator.php#L347-L391
mossadal/math-parser
src/MathParser/Interpreting/RationalEvaluator.php
RationalEvaluator.powerFreeFactorization
public static function powerFreeFactorization($n, $d) { $factors = self::ifactor($n); $square = 1; $nonSquare = 1; foreach ($factors as $prime => $exponent) { $remainder = $exponent % $d; if ($remainder != 0) { $reducedExponent = ($exponent ...
php
public static function powerFreeFactorization($n, $d) { $factors = self::ifactor($n); $square = 1; $nonSquare = 1; foreach ($factors as $prime => $exponent) { $remainder = $exponent % $d; if ($remainder != 0) { $reducedExponent = ($exponent ...
[ "public", "static", "function", "powerFreeFactorization", "(", "$", "n", ",", "$", "d", ")", "{", "$", "factors", "=", "self", "::", "ifactor", "(", "$", "n", ")", ";", "$", "square", "=", "1", ";", "$", "nonSquare", "=", "1", ";", "foreach", "(", ...
Compute a power free integer factorization: n = pq^d, where p is d-power free. The function returns an array: [ 'square' => q, 'nonSquare' => p ] @param int $n input
[ "Compute", "a", "power", "free", "integer", "factorization", ":", "n", "=", "pq^d", "where", "p", "is", "d", "-", "power", "free", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/RationalEvaluator.php#L405-L425
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/DivisionNodeFactory.php
DivisionNodeFactory.makeNode
public function makeNode($leftOperand, $rightOperand) { $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); // Return rational number? // if ($leftOperand instanceof NumberNode && $rightOperand instanceof NumberNode) // return new...
php
public function makeNode($leftOperand, $rightOperand) { $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); // Return rational number? // if ($leftOperand instanceof NumberNode && $rightOperand instanceof NumberNode) // return new...
[ "public", "function", "makeNode", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "$", "leftOperand", "=", "$", "this", "->", "sanitize", "(", "$", "leftOperand", ")", ";", "$", "rightOperand", "=", "$", "this", "->", "sanitize", "(", "$", ...
Create a Node representing '$leftOperand/$rightOperand' Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing '$leftOperand/$rightOperand'. ### Simplification rules: - To simplify the use of the function, convert integer params to NumberNodes - If $leftOperand is...
[ "Create", "a", "Node", "representing", "$leftOperand", "/", "$rightOperand" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/DivisionNodeFactory.php#L54-L71
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/DivisionNodeFactory.php
DivisionNodeFactory.numericFactors
protected function numericFactors($leftOperand, $rightOperand) { if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 0) { throw new DivisionByZeroException(); } if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 1) { return $le...
php
protected function numericFactors($leftOperand, $rightOperand) { if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 0) { throw new DivisionByZeroException(); } if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 1) { return $le...
[ "protected", "function", "numericFactors", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "if", "(", "$", "this", "->", "isNumeric", "(", "$", "rightOperand", ")", "&&", "$", "rightOperand", "->", "getValue", "(", ")", "==", "0", ")", "{", ...
Simplify division nodes when factors are numeric @param Node $leftOperand @param Node $rightOperand @retval Node|null
[ "Simplify", "division", "nodes", "when", "factors", "are", "numeric" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/DivisionNodeFactory.php#L78-L109
mossadal/math-parser
src/MathParser/Parsing/Nodes/Traits/Sanitize.php
Sanitize.sanitize
protected function sanitize($operand) { if (is_int($operand)) return new IntegerNode($operand); if (is_float($operand)) return new NumberNode($operand); return $operand; }
php
protected function sanitize($operand) { if (is_int($operand)) return new IntegerNode($operand); if (is_float($operand)) return new NumberNode($operand); return $operand; }
[ "protected", "function", "sanitize", "(", "$", "operand", ")", "{", "if", "(", "is_int", "(", "$", "operand", ")", ")", "return", "new", "IntegerNode", "(", "$", "operand", ")", ";", "if", "(", "is_float", "(", "$", "operand", ")", ")", "return", "ne...
Convert ints and floats to NumberNodes @param Node|int|float $operand @retval Node
[ "Convert", "ints", "and", "floats", "to", "NumberNodes" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Traits/Sanitize.php#L33-L39
mossadal/math-parser
src/MathParser/Interpreting/Differentiator.php
Differentiator.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $leftValue = $node->getLeft()->accept($this); if ($node->getRight()) { $rightValue = $node->getRight()->accept($this); } else { $rightValue = null; } ...
php
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $leftValue = $node->getLeft()->accept($this); if ($node->getRight()) { $rightValue = $node->getRight()->accept($this); } else { $rightValue = null; } ...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "operator", "=", "$", "node", "->", "getOperator", "(", ")", ";", "$", "leftValue", "=", "$", "node", "->", "getLeft", "(", ")", "->", "accept", "(", "$", "...
Differentiate an ExpressionNode Using the usual rules for differentiating, create an ExpressionNode giving an AST correctly representing the derivative `(x op y)'` where `op` is one of `+`, `-`, `*`, `/` or `^` ### Differentiation rules: - \\( (f+g)' = f' + g' \\) - \\( (f-g) ' = f' - g' \\) - \\( (-f)' = -f' \\) - ...
[ "Differentiate", "an", "ExpressionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/Differentiator.php#L101-L166
mossadal/math-parser
src/MathParser/Interpreting/Differentiator.php
Differentiator.visitFunctionNode
public function visitFunctionNode(FunctionNode $node) { $inner = $node->getOperand()->accept($this); $arg = $node->getOperand(); switch ($node->getName()) { case 'sin': $df = new FunctionNode('cos', $arg); break; case 'cos': ...
php
public function visitFunctionNode(FunctionNode $node) { $inner = $node->getOperand()->accept($this); $arg = $node->getOperand(); switch ($node->getName()) { case 'sin': $df = new FunctionNode('cos', $arg); break; case 'cos': ...
[ "public", "function", "visitFunctionNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "inner", "=", "$", "node", "->", "getOperand", "(", ")", "->", "accept", "(", "$", "this", ")", ";", "$", "arg", "=", "$", "node", "->", "getOperand", "(", ")...
Differentiate a FunctionNode Create an ExpressionNode giving an AST correctly representing the derivative `f'` where `f` is an elementary function. ### Differentiation rules: \\( \\sin(f(x))' = f'(x) \\cos(f(x)) \\) \\( \\cos(f(x))' = -f'(x) \\sin(f(x)) \\) \\( \\tan(f(x))' = f'(x) (1 + \\tan(f(x))^2 \\) \\( \\ope...
[ "Differentiate", "a", "FunctionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/Differentiator.php#L244-L347
mossadal/math-parser
src/MathParser/Parsing/Nodes/NumberNode.php
NumberNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof NumberNode)) { return false; } return $this->getValue() == $other->getValue(); }
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof NumberNode)) { return false; } return $this->getValue() == $other->getValue(); }
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "NumberNode", ")", ")", "{", "return", "false", ";", "}"...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/NumberNode.php#L46-L56
mossadal/math-parser
src/MathParser/Interpreting/TreePrinter.php
TreePrinter.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $leftValue = $node->getLeft()->accept($this); $operator = $node->getOperator(); // The operator and the right side are optional, remember? if (!$operator) return "$leftValue"; $right = $node->getRight()...
php
public function visitExpressionNode(ExpressionNode $node) { $leftValue = $node->getLeft()->accept($this); $operator = $node->getOperator(); // The operator and the right side are optional, remember? if (!$operator) return "$leftValue"; $right = $node->getRight()...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "leftValue", "=", "$", "node", "->", "getLeft", "(", ")", "->", "accept", "(", "$", "this", ")", ";", "$", "operator", "=", "$", "node", "->", "getOperator", ...
Print an ExpressionNode. @param ExpressionNode $node
[ "Print", "an", "ExpressionNode", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/TreePrinter.php#L43-L61
mossadal/math-parser
src/MathParser/Interpreting/TreePrinter.php
TreePrinter.visitFunctionNode
public function visitFunctionNode(FunctionNode $node) { $functionName = $node->getName(); $operand = $node->getOperand()->accept($this); return "$functionName($operand)"; }
php
public function visitFunctionNode(FunctionNode $node) { $functionName = $node->getName(); $operand = $node->getOperand()->accept($this); return "$functionName($operand)"; }
[ "public", "function", "visitFunctionNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "functionName", "=", "$", "node", "->", "getName", "(", ")", ";", "$", "operand", "=", "$", "node", "->", "getOperand", "(", ")", "->", "accept", "(", "$", "thi...
Print a FunctionNode. @param FunctionNode $node
[ "Print", "a", "FunctionNode", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/TreePrinter.php#L100-L106
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.parse
public function parse(array $tokens) { // Filter away any whitespace $tokens = $this->filterTokens($tokens); // Insert missing implicit multiplication tokens if (static::allowImplicitMultiplication()) { $tokens = $this->parseImplicitMultiplication($tokens); } ...
php
public function parse(array $tokens) { // Filter away any whitespace $tokens = $this->filterTokens($tokens); // Insert missing implicit multiplication tokens if (static::allowImplicitMultiplication()) { $tokens = $this->parseImplicitMultiplication($tokens); } ...
[ "public", "function", "parse", "(", "array", "$", "tokens", ")", "{", "// Filter away any whitespace", "$", "tokens", "=", "$", "this", "->", "filterTokens", "(", "$", "tokens", ")", ";", "// Insert missing implicit multiplication tokens", "if", "(", "static", "::...
Parse list of tokens @param array $tokens Array (Token[]) of input tokens. @retval Node AST representing the parsed expression.
[ "Parse", "list", "of", "tokens" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L111-L125
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.shuntingYard
private function shuntingYard(array $tokens) { // Clear the oepratorStack $this->operatorStack = new Stack(); // Clear the operandStack. $this->operandStack = new Stack(); // Remember the last token handled, this is done to recognize unary operators. $lastNode = nul...
php
private function shuntingYard(array $tokens) { // Clear the oepratorStack $this->operatorStack = new Stack(); // Clear the operandStack. $this->operandStack = new Stack(); // Remember the last token handled, this is done to recognize unary operators. $lastNode = nul...
[ "private", "function", "shuntingYard", "(", "array", "$", "tokens", ")", "{", "// Clear the oepratorStack", "$", "this", "->", "operatorStack", "=", "new", "Stack", "(", ")", ";", "// Clear the operandStack.", "$", "this", "->", "operandStack", "=", "new", "Stac...
Implementation of the shunting yard parsing algorithm @param array $tokens Token[] array of tokens to process @retval Node AST of the parsed expression @throws SyntaxErrorException @throws ParenthesisMismatchException
[ "Implementation", "of", "the", "shunting", "yard", "parsing", "algorithm" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L135-L231
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.handleExpression
protected function handleExpression($node) { if ($node instanceof FunctionNode) throw new ParenthesisMismatchException($node->getOperator()); if ($node instanceof SubExpressionNode) throw new ParenthesisMismatchException($node->getOperator()); if (!$this->simplifyingParser) return $this->na...
php
protected function handleExpression($node) { if ($node instanceof FunctionNode) throw new ParenthesisMismatchException($node->getOperator()); if ($node instanceof SubExpressionNode) throw new ParenthesisMismatchException($node->getOperator()); if (!$this->simplifyingParser) return $this->na...
[ "protected", "function", "handleExpression", "(", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "FunctionNode", ")", "throw", "new", "ParenthesisMismatchException", "(", "$", "node", "->", "getOperator", "(", ")", ")", ";", "if", "(", "$", "...
Populate node with operands. @param Node $node @retval Node @throws SyntaxErrorException
[ "Populate", "node", "with", "operands", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L241-L283
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.naiveHandleExpression
protected function naiveHandleExpression($node) { if ($node->getOperator() == '~') { $left = $this->operandStack->pop(); if ($left === null) { throw new SyntaxErrorException(); } $node->setOperator('-'); $node->setLeft($left); ...
php
protected function naiveHandleExpression($node) { if ($node->getOperator() == '~') { $left = $this->operandStack->pop(); if ($left === null) { throw new SyntaxErrorException(); } $node->setOperator('-'); $node->setLeft($left); ...
[ "protected", "function", "naiveHandleExpression", "(", "$", "node", ")", "{", "if", "(", "$", "node", "->", "getOperator", "(", ")", "==", "'~'", ")", "{", "$", "left", "=", "$", "this", "->", "operandStack", "->", "pop", "(", ")", ";", "if", "(", ...
Populate node with operands, without any simplification. @param Node $node @retval Node @throws SyntaxErrorException
[ "Populate", "node", "with", "operands", "without", "any", "simplification", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L292-L317
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.filterTokens
protected function filterTokens(array $tokens) { $filteredTokens = array_filter($tokens, function (Token $t) { return $t->getType() !== TokenType::Whitespace; }); // Return the array values only, because array_filter preserves the keys return array_values($filteredTokens...
php
protected function filterTokens(array $tokens) { $filteredTokens = array_filter($tokens, function (Token $t) { return $t->getType() !== TokenType::Whitespace; }); // Return the array values only, because array_filter preserves the keys return array_values($filteredTokens...
[ "protected", "function", "filterTokens", "(", "array", "$", "tokens", ")", "{", "$", "filteredTokens", "=", "array_filter", "(", "$", "tokens", ",", "function", "(", "Token", "$", "t", ")", "{", "return", "$", "t", "->", "getType", "(", ")", "!==", "To...
Remove Whitespace from the token list. @param array $tokens Input list of tokens @retval Token[]
[ "Remove", "Whitespace", "from", "the", "token", "list", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L325-L333
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.parseImplicitMultiplication
protected function parseImplicitMultiplication(array $tokens) { $result = []; $lastToken = null; foreach ($tokens as $token) { if (Token::canFactorsInImplicitMultiplication($lastToken, $token)) { $result[] = new Token('*', TokenType::MultiplicationOperator); ...
php
protected function parseImplicitMultiplication(array $tokens) { $result = []; $lastToken = null; foreach ($tokens as $token) { if (Token::canFactorsInImplicitMultiplication($lastToken, $token)) { $result[] = new Token('*', TokenType::MultiplicationOperator); ...
[ "protected", "function", "parseImplicitMultiplication", "(", "array", "$", "tokens", ")", "{", "$", "result", "=", "[", "]", ";", "$", "lastToken", "=", "null", ";", "foreach", "(", "$", "tokens", "as", "$", "token", ")", "{", "if", "(", "Token", "::",...
Insert multiplication tokens where needed (taking care of implicit mulitplication). @param array $tokens Input list of tokens (Token[]) @retval Token[]
[ "Insert", "multiplication", "tokens", "where", "needed", "(", "taking", "care", "of", "implicit", "mulitplication", ")", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L341-L353
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.isUnary
protected function isUnary($node, $lastNode) { if (!($node->canBeUnary())) return false; // Unary if it is the first token if ($this->operatorStack->isEmpty() && $this->operandStack->isEmpty()) return true; // or if the previous token was '(' if ($lastNode instanceof SubExpr...
php
protected function isUnary($node, $lastNode) { if (!($node->canBeUnary())) return false; // Unary if it is the first token if ($this->operatorStack->isEmpty() && $this->operandStack->isEmpty()) return true; // or if the previous token was '(' if ($lastNode instanceof SubExpr...
[ "protected", "function", "isUnary", "(", "$", "node", ",", "$", "lastNode", ")", "{", "if", "(", "!", "(", "$", "node", "->", "canBeUnary", "(", ")", ")", ")", "return", "false", ";", "// Unary if it is the first token", "if", "(", "$", "this", "->", "...
Determine if $node is in fact a unary operator. If $node can be a unary operator (i.e. is a '+' or '-' node), **and** this is the first node we parse or the previous node was a SubExpressionNode, i.e. an opening parenthesis, or the previous node was already a unary minus, this means that the current node is in fact a ...
[ "Determine", "if", "$node", "is", "in", "fact", "a", "unary", "operator", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L396-L408
mossadal/math-parser
src/MathParser/Parsing/Parser.php
Parser.handleSubExpression
protected function handleSubExpression() { // Flag, checking for mismatching parentheses $clean = false; // Pop operators off the operatorStack until its empty, or // we find an opening parenthesis, building subexpressions // on the operandStack as we go. while ($pop...
php
protected function handleSubExpression() { // Flag, checking for mismatching parentheses $clean = false; // Pop operators off the operatorStack until its empty, or // we find an opening parenthesis, building subexpressions // on the operandStack as we go. while ($pop...
[ "protected", "function", "handleSubExpression", "(", ")", "{", "// Flag, checking for mismatching parentheses", "$", "clean", "=", "false", ";", "// Pop operators off the operatorStack until its empty, or", "// we find an opening parenthesis, building subexpressions", "// on the operandS...
Handle a closing parenthesis, popping operators off the operator stack until we find a matching opening parenthesis. @throws ParenthesisMismatchException
[ "Handle", "a", "closing", "parenthesis", "popping", "operators", "off", "the", "operator", "stack", "until", "we", "find", "a", "matching", "opening", "parenthesis", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Parser.php#L415-L452
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/ExponentiationNodeFactory.php
ExponentiationNodeFactory.makeNode
public function makeNode($leftOperand, $rightOperand) { $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); // Simplification if the exponent is a number. if ($this->isNumeric($rightOperand)) { $node = $this->numericExponent($lef...
php
public function makeNode($leftOperand, $rightOperand) { $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); // Simplification if the exponent is a number. if ($this->isNumeric($rightOperand)) { $node = $this->numericExponent($lef...
[ "public", "function", "makeNode", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "$", "leftOperand", "=", "$", "this", "->", "sanitize", "(", "$", "leftOperand", ")", ";", "$", "rightOperand", "=", "$", "this", "->", "sanitize", "(", "$", ...
Create a Node representing '$leftOperand^$rightOperand' Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing '$leftOperand^$rightOperand'. ### Simplification rules: - To simplify the use of the function, convert integer params to NumberNodes - If $leftOperand an...
[ "Create", "a", "Node", "representing", "$leftOperand^$rightOperand" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/ExponentiationNodeFactory.php#L54-L69
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/ExponentiationNodeFactory.php
ExponentiationNodeFactory.numericExponent
private function numericExponent($leftOperand, $rightOperand) { // 0^0 throws an exception if ($this->isNumeric($leftOperand) && $this->isNumeric($rightOperand)) { if ($leftOperand->getValue() == 0 && $rightOperand->getValue() == 0) throw new DivisionByZeroException(); ...
php
private function numericExponent($leftOperand, $rightOperand) { // 0^0 throws an exception if ($this->isNumeric($leftOperand) && $this->isNumeric($rightOperand)) { if ($leftOperand->getValue() == 0 && $rightOperand->getValue() == 0) throw new DivisionByZeroException(); ...
[ "private", "function", "numericExponent", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "// 0^0 throws an exception", "if", "(", "$", "this", "->", "isNumeric", "(", "$", "leftOperand", ")", "&&", "$", "this", "->", "isNumeric", "(", "$", "rig...
Simplify an expression x^y, when y is numeric. @param Node $leftOperand @param Node $rightOperand @retval Node|null
[ "Simplify", "an", "expression", "x^y", "when", "y", "is", "numeric", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/ExponentiationNodeFactory.php#L77-L109
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/ExponentiationNodeFactory.php
ExponentiationNodeFactory.doubleExponentiation
private function doubleExponentiation($leftOperand, $rightOperand) { // (x^a)^b -> x^(ab) for a, b numbers if ($leftOperand instanceof ExpressionNode && $leftOperand->getOperator() == '^') { $factory = new MultiplicationNodeFactory(); $power = $factory->makeNode($leftOperand...
php
private function doubleExponentiation($leftOperand, $rightOperand) { // (x^a)^b -> x^(ab) for a, b numbers if ($leftOperand instanceof ExpressionNode && $leftOperand->getOperator() == '^') { $factory = new MultiplicationNodeFactory(); $power = $factory->makeNode($leftOperand...
[ "private", "function", "doubleExponentiation", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "// (x^a)^b -> x^(ab) for a, b numbers", "if", "(", "$", "leftOperand", "instanceof", "ExpressionNode", "&&", "$", "leftOperand", "->", "getOperator", "(", ")",...
Simplify (x^a)^b when a and b are both numeric. @param Node $leftOperand @param Node $rightOperand @retval Node|null
[ "Simplify", "(", "x^a", ")", "^b", "when", "a", "and", "b", "are", "both", "numeric", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/ExponentiationNodeFactory.php#L116-L130
mossadal/math-parser
src/MathParser/Parsing/Nodes/Node.php
Node.rationalFactory
public static function rationalFactory(Token $token) { switch ($token->getType()) { case TokenType::PosInt: case TokenType::Integer: $x = intval($token->getValue()); return new IntegerNode($x); case TokenType::RealNumber: $...
php
public static function rationalFactory(Token $token) { switch ($token->getType()) { case TokenType::PosInt: case TokenType::Integer: $x = intval($token->getValue()); return new IntegerNode($x); case TokenType::RealNumber: $...
[ "public", "static", "function", "rationalFactory", "(", "Token", "$", "token", ")", "{", "switch", "(", "$", "token", "->", "getType", "(", ")", ")", "{", "case", "TokenType", "::", "PosInt", ":", "case", "TokenType", "::", "Integer", ":", "$", "x", "=...
Node factory, creating an appropriate Node from a Token. Based on the provided Token, returns a TerminalNode if the token type is PosInt, Integer, RealNumber, Identifier or Constant otherwise returns null. @retval Node|null @param Token $token Provided token
[ "Node", "factory", "creating", "an", "appropriate", "Node", "from", "a", "Token", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Node.php#L44-L80
mossadal/math-parser
src/MathParser/Parsing/Nodes/Node.php
Node.complexity
public function complexity() { if ($this instanceof IntegerNode || $this instanceof VariableNode || $this instanceof ConstantNode) { return 1; } elseif ($this instanceof RationalNode || $this instanceof NumberNode) { return 2; } elseif ($this instanceof FunctionNode) ...
php
public function complexity() { if ($this instanceof IntegerNode || $this instanceof VariableNode || $this instanceof ConstantNode) { return 1; } elseif ($this instanceof RationalNode || $this instanceof NumberNode) { return 2; } elseif ($this instanceof FunctionNode) ...
[ "public", "function", "complexity", "(", ")", "{", "if", "(", "$", "this", "instanceof", "IntegerNode", "||", "$", "this", "instanceof", "VariableNode", "||", "$", "this", "instanceof", "ConstantNode", ")", "{", "return", "1", ";", "}", "elseif", "(", "$",...
Rough estimate of the complexity of the AST. Gives a rough measure of the complexity of an AST. This can be useful to choose between different simplification rules or how to print a tree ("e^{...}" or ("\exp(...)") for example. More precisely, the complexity is computed as the sum of the complexity of all nodes of th...
[ "Rough", "estimate", "of", "the", "complexity", "of", "the", "AST", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Node.php#L177-L205
mossadal/math-parser
src/MathParser/Parsing/Nodes/Node.php
Node.isTerminal
public function isTerminal() { if ($this instanceof NumberNode) { return true; } if ($this instanceof IntegerNode) { return true; } if ($this instanceof RationalNode) { return true; } if ($this instanceof VariableNode) { ...
php
public function isTerminal() { if ($this instanceof NumberNode) { return true; } if ($this instanceof IntegerNode) { return true; } if ($this instanceof RationalNode) { return true; } if ($this instanceof VariableNode) { ...
[ "public", "function", "isTerminal", "(", ")", "{", "if", "(", "$", "this", "instanceof", "NumberNode", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "instanceof", "IntegerNode", ")", "{", "return", "true", ";", "}", "if", "(", "$", "t...
Returns true if the node is a terminal node, i.e. a NumerNode, VariableNode or ConstantNode. @retval boolean
[ "Returns", "true", "if", "the", "node", "is", "a", "terminal", "node", "i", ".", "e", ".", "a", "NumerNode", "VariableNode", "or", "ConstantNode", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Node.php#L214-L237
mossadal/math-parser
src/MathParser/Lexing/TokenDefinition.php
TokenDefinition.match
public function match($input) { // Match the input with the regex pattern, storing any match found into the $matches variable, // along with the index of the string at which it was matched. $result = preg_match($this->pattern, $input, $matches, PREG_OFFSET_CAPTURE); // preg_match re...
php
public function match($input) { // Match the input with the regex pattern, storing any match found into the $matches variable, // along with the index of the string at which it was matched. $result = preg_match($this->pattern, $input, $matches, PREG_OFFSET_CAPTURE); // preg_match re...
[ "public", "function", "match", "(", "$", "input", ")", "{", "// Match the input with the regex pattern, storing any match found into the $matches variable,", "// along with the index of the string at which it was matched.", "$", "result", "=", "preg_match", "(", "$", "this", "->", ...
Try to match the given input to the current TokenDefinition. @param string $input Input string @retval Token|null Token matching the regular expression defining the TokenDefinition
[ "Try", "to", "match", "the", "given", "input", "to", "the", "current", "TokenDefinition", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Lexing/TokenDefinition.php#L60-L75
mossadal/math-parser
src/MathParser/Lexing/TokenDefinition.php
TokenDefinition.getTokenFromMatch
private function getTokenFromMatch($match) { $value = $match[0]; $offset = $match[1]; // If we don't match at the beginning of the string, it fails. if ($offset !== 0) return null; if ($this->value) $value = $this->value; return new Token($value, $this-...
php
private function getTokenFromMatch($match) { $value = $match[0]; $offset = $match[1]; // If we don't match at the beginning of the string, it fails. if ($offset !== 0) return null; if ($this->value) $value = $this->value; return new Token($value, $this-...
[ "private", "function", "getTokenFromMatch", "(", "$", "match", ")", "{", "$", "value", "=", "$", "match", "[", "0", "]", ";", "$", "offset", "=", "$", "match", "[", "1", "]", ";", "// If we don't match at the beginning of the string, it fails.", "if", "(", "...
Convert matching string to an actual Token. @param string $match Matching text. @retval Token Corresponding token.
[ "Convert", "matching", "string", "to", "an", "actual", "Token", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Lexing/TokenDefinition.php#L83-L95
mossadal/math-parser
src/MathParser/Parsing/Nodes/FunctionNode.php
FunctionNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof FunctionNode)) { return false; } $thisOperand = $this->getOperand(); $otherOperand = $other->getOperand(); return $this->getName() == $...
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof FunctionNode)) { return false; } $thisOperand = $this->getOperand(); $otherOperand = $other->getOperand(); return $this->getName() == $...
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "FunctionNode", ")", ")", "{", "return", "false", ";", "...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/FunctionNode.php#L73-L86
mossadal/math-parser
src/MathParser/Interpreting/Evaluator.php
Evaluator.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $leftValue = $node->getLeft()->accept($this); if ($node->getRight()) { $rightValue = $node->getRight()->accept($this); } else { $rightValue = null; } ...
php
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $leftValue = $node->getLeft()->accept($this); if ($node->getRight()) { $rightValue = $node->getRight()->accept($this); } else { $rightValue = null; } ...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "operator", "=", "$", "node", "->", "getOperator", "(", ")", ";", "$", "leftValue", "=", "$", "node", "->", "getLeft", "(", ")", "->", "accept", "(", "$", "...
Evaluate an ExpressionNode Computes the value of an ExpressionNode `x op y` where `op` is one of `+`, `-`, `*`, `/` or `^` `+`, `-`, `*`, `/` or `^` @retval float @param ExpressionNode $node AST to be evaluated @throws UnknownOperatorException if the operator is something other than
[ "Evaluate", "an", "ExpressionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/Evaluator.php#L91-L130
mossadal/math-parser
src/MathParser/Interpreting/Evaluator.php
Evaluator.visitFunctionNode
public function visitFunctionNode(FunctionNode $node) { $inner = $node->getOperand()->accept($this); switch ($node->getName()) { // Trigonometric functions case 'sin': return sin($inner); case 'cos': return cos($inner); ...
php
public function visitFunctionNode(FunctionNode $node) { $inner = $node->getOperand()->accept($this); switch ($node->getName()) { // Trigonometric functions case 'sin': return sin($inner); case 'cos': return cos($inner); ...
[ "public", "function", "visitFunctionNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "inner", "=", "$", "node", "->", "getOperand", "(", ")", "->", "accept", "(", "$", "this", ")", ";", "switch", "(", "$", "node", "->", "getName", "(", ")", ")...
Evaluate a FunctionNode Computes the value of a FunctionNode `f(x)`, where f is an elementary function recognized by StdMathLexer and StdMathParser. FunctionNode is *not* recognized. @retval float @see \MathParser\Lexer\StdMathLexer StdMathLexer @see \MathParser\StdMathParser StdMathParser @param FunctionNode ...
[ "Evaluate", "a", "FunctionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/Evaluator.php#L193-L324
mossadal/math-parser
src/MathParser/Interpreting/Evaluator.php
Evaluator.visitConstantNode
public function visitConstantNode(ConstantNode $node) { switch ($node->getName()) { case 'pi': return M_PI; case 'e': return exp(1); case 'NAN': return NAN; case 'INF': return INF; def...
php
public function visitConstantNode(ConstantNode $node) { switch ($node->getName()) { case 'pi': return M_PI; case 'e': return exp(1); case 'NAN': return NAN; case 'INF': return INF; def...
[ "public", "function", "visitConstantNode", "(", "ConstantNode", "$", "node", ")", "{", "switch", "(", "$", "node", "->", "getName", "(", ")", ")", "{", "case", "'pi'", ":", "return", "M_PI", ";", "case", "'e'", ":", "return", "exp", "(", "1", ")", ";...
Evaluate a ConstantNode Returns the value of a ConstantNode recognized by StdMathLexer and StdMathParser. ConstantNode is *not* recognized. @retval float @see \MathParser\Lexer\StdMathLexer StdMathLexer @see \MathParser\StdMathParser StdMathParser @param ConstantNode $node AST to be evaluated @throws Un...
[ "Evaluate", "a", "ConstantNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/Evaluator.php#L339-L353
mossadal/math-parser
src/MathParser/RationalMathParser.php
RationalMathParser.parse
public function parse($text) { $this->tokens = $this->lexer->tokenize($text); $this->tree = $this->parser->parse($this->tokens); return $this->tree; }
php
public function parse($text) { $this->tokens = $this->lexer->tokenize($text); $this->tree = $this->parser->parse($this->tokens); return $this->tree; }
[ "public", "function", "parse", "(", "$", "text", ")", "{", "$", "this", "->", "tokens", "=", "$", "this", "->", "lexer", "->", "tokenize", "(", "$", "text", ")", ";", "$", "this", "->", "tree", "=", "$", "this", "->", "parser", "->", "parse", "("...
Parse the given mathematical expression into an abstract syntax tree. @param string $text Input @retval Node
[ "Parse", "the", "given", "mathematical", "expression", "into", "an", "abstract", "syntax", "tree", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/RationalMathParser.php#L53-L59
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/SubtractionNodeFactory.php
SubtractionNodeFactory.makeNode
public function makeNode($leftOperand, $rightOperand) { if ($rightOperand === null) return $this->createUnaryMinusNode($leftOperand); $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); $node = $this->numericTerms($leftOperand, $rightOperan...
php
public function makeNode($leftOperand, $rightOperand) { if ($rightOperand === null) return $this->createUnaryMinusNode($leftOperand); $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); $node = $this->numericTerms($leftOperand, $rightOperan...
[ "public", "function", "makeNode", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "if", "(", "$", "rightOperand", "===", "null", ")", "return", "$", "this", "->", "createUnaryMinusNode", "(", "$", "leftOperand", ")", ";", "$", "leftOperand", "...
Create a Node representing 'leftOperand - rightOperand' Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing 'rightOperand - leftOperand'. ### Simplification rules: - To simplify the use of the function, convert integer params to NumberNodes - If $rightOperand i...
[ "Create", "a", "Node", "representing", "leftOperand", "-", "rightOperand" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/SubtractionNodeFactory.php#L52-L67
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/SubtractionNodeFactory.php
SubtractionNodeFactory.createUnaryMinusNode
public function createUnaryMinusNode($operand) { $operand = $this->sanitize($operand); if ($operand instanceof NumberNode) { return new NumberNode(-$operand->getValue()); } if ($operand instanceof IntegerNode) { return new IntegerNode(-$operand->getValue()); ...
php
public function createUnaryMinusNode($operand) { $operand = $this->sanitize($operand); if ($operand instanceof NumberNode) { return new NumberNode(-$operand->getValue()); } if ($operand instanceof IntegerNode) { return new IntegerNode(-$operand->getValue()); ...
[ "public", "function", "createUnaryMinusNode", "(", "$", "operand", ")", "{", "$", "operand", "=", "$", "this", "->", "sanitize", "(", "$", "operand", ")", ";", "if", "(", "$", "operand", "instanceof", "NumberNode", ")", "{", "return", "new", "NumberNode", ...
Create a Node representing '-$operand' Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing '-$operand'. ### Simplification rules: - To simplify the use of the function, convert integer params to NumberNodes - If $operand is a NumberNodes, return a single Number...
[ "Create", "a", "Node", "representing", "-", "$operand" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/SubtractionNodeFactory.php#L115-L133
mossadal/math-parser
src/MathParser/Parsing/Nodes/VariableNode.php
VariableNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof VariableNode)) { return false; } return $this->getName() == $other->getName(); }
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof VariableNode)) { return false; } return $this->getName() == $other->getName(); }
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "VariableNode", ")", ")", "{", "return", "false", ";", "...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/VariableNode.php#L46-L56
mossadal/math-parser
src/MathParser/Parsing/Nodes/IntegerNode.php
IntegerNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if ($other instanceof RationalNode) { return $other->getDenominator() == 1 && $this->getValue() == $other->getNumerator(); } if (!($other instanceof IntegerNode)) { ...
php
public function compareTo($other) { if ($other === null) { return false; } if ($other instanceof RationalNode) { return $other->getDenominator() == 1 && $this->getValue() == $other->getNumerator(); } if (!($other instanceof IntegerNode)) { ...
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "$", "other", "instanceof", "RationalNode", ")", "{", "return", "$", "other", "->", "getDenominato...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/IntegerNode.php#L58-L71
mossadal/math-parser
src/MathParser/Interpreting/LaTeXPrinter.php
LaTeXPrinter.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $left = $node->getLeft(); $right = $node->getRight(); switch ($operator) { case '+': $leftValue = $left->accept($this); $rightValue = $this->par...
php
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $left = $node->getLeft(); $right = $node->getRight(); switch ($operator) { case '+': $leftValue = $left->accept($this); $rightValue = $this->par...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "operator", "=", "$", "node", "->", "getOperator", "(", ")", ";", "$", "left", "=", "$", "node", "->", "getLeft", "(", ")", ";", "$", "right", "=", "$", "...
Generate LaTeX code for an ExpressionNode Create a string giving LaTeX code for an ExpressionNode `(x op y)` where `op` is one of `+`, `-`, `*`, `/` or `^` ### Typesetting rules: - Adds parentheses around each operand, if needed. (I.e. if their precedence lower than that of the current Node.) For example, the AST `(...
[ "Generate", "LaTeX", "code", "for", "an", "ExpressionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/LaTeXPrinter.php#L86-L146
mossadal/math-parser
src/MathParser/Interpreting/LaTeXPrinter.php
LaTeXPrinter.MultiplicationNeedsCdot
private function MultiplicationNeedsCdot($left, $right) { if ($left instanceof FunctionNode) { return true; } if ($this->isNumeric($right)) { return true; } if ($right instanceof ExpressionNode && $this->isNumeric($right->getLeft())) { re...
php
private function MultiplicationNeedsCdot($left, $right) { if ($left instanceof FunctionNode) { return true; } if ($this->isNumeric($right)) { return true; } if ($right instanceof ExpressionNode && $this->isNumeric($right->getLeft())) { re...
[ "private", "function", "MultiplicationNeedsCdot", "(", "$", "left", ",", "$", "right", ")", "{", "if", "(", "$", "left", "instanceof", "FunctionNode", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "isNumeric", "(", "$", "right", "...
Check if a multiplication needs an inserted \cdot or if it can be safely written with implicit multiplication. @retval bool @param $left AST of first factor @param $right AST of second factor
[ "Check", "if", "a", "multiplication", "needs", "an", "inserted", "\\", "cdot", "or", "if", "it", "can", "be", "safely", "written", "with", "implicit", "multiplication", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/LaTeXPrinter.php#L156-L171
mossadal/math-parser
src/MathParser/Interpreting/LaTeXPrinter.php
LaTeXPrinter.visitFactorialNode
private function visitFactorialNode(FunctionNode $node) { $functionName = $node->getName(); $op = $node->getOperand(); $operand = $op->accept($this); // Add parentheses most of the time. if ($this->isNumeric($op)) { if ($op->getValue() < 0) { $ope...
php
private function visitFactorialNode(FunctionNode $node) { $functionName = $node->getName(); $op = $node->getOperand(); $operand = $op->accept($this); // Add parentheses most of the time. if ($this->isNumeric($op)) { if ($op->getValue() < 0) { $ope...
[ "private", "function", "visitFactorialNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "functionName", "=", "$", "node", "->", "getName", "(", ")", ";", "$", "op", "=", "$", "node", "->", "getOperand", "(", ")", ";", "$", "operand", "=", "$", ...
Generate LaTeX code for factorials @retval string @param FunctionNode $node AST to be typeset
[ "Generate", "LaTeX", "code", "for", "factorials" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/LaTeXPrinter.php#L232-L250
mossadal/math-parser
src/MathParser/Interpreting/LaTeXPrinter.php
LaTeXPrinter.visitFunctionNode
public function visitFunctionNode(FunctionNode $node) { $functionName = $node->getName(); $operand = $node->getOperand()->accept($this); switch ($functionName) { case 'sqrt': return "\\$functionName{" . $node->getOperand()->accept($this) . '}'; case ...
php
public function visitFunctionNode(FunctionNode $node) { $functionName = $node->getName(); $operand = $node->getOperand()->accept($this); switch ($functionName) { case 'sqrt': return "\\$functionName{" . $node->getOperand()->accept($this) . '}'; case ...
[ "public", "function", "visitFunctionNode", "(", "FunctionNode", "$", "node", ")", "{", "$", "functionName", "=", "$", "node", "->", "getName", "(", ")", ";", "$", "operand", "=", "$", "node", "->", "getOperand", "(", ")", "->", "accept", "(", "$", "thi...
Generate LaTeX code for a FunctionNode Create a string giving LaTeX code for a functionNode. ### Typesetting rules: - `sqrt(op)` is typeset as `\sqrt{op} - `exp(op)` is either typeset as `e^{op}`, if `op` is a simple expression or as `\exp(op)` for more complicated operands. @retval string @param FunctionNode $node...
[ "Generate", "LaTeX", "code", "for", "a", "FunctionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/LaTeXPrinter.php#L267-L314
mossadal/math-parser
src/MathParser/Interpreting/LaTeXPrinter.php
LaTeXPrinter.parenthesize
public function parenthesize(Node $node, ExpressionNode $cutoff, $prepend = '', $conservative = false) { $text = $node->accept($this); if ($node instanceof ExpressionNode) { // Second term is a unary minus if ($node->getOperator() == '-' && $node->getRight() == null) { ...
php
public function parenthesize(Node $node, ExpressionNode $cutoff, $prepend = '', $conservative = false) { $text = $node->accept($this); if ($node instanceof ExpressionNode) { // Second term is a unary minus if ($node->getOperator() == '-' && $node->getRight() == null) { ...
[ "public", "function", "parenthesize", "(", "Node", "$", "node", ",", "ExpressionNode", "$", "cutoff", ",", "$", "prepend", "=", "''", ",", "$", "conservative", "=", "false", ")", "{", "$", "text", "=", "$", "node", "->", "accept", "(", "$", "this", "...
Add parentheses to the LaTeX representation of $node if needed. node. Operands with a lower precedence have parentheses added. be added at the beginning of the returned string. @retval string @param Node $node The AST to typeset @param ExpressionNode $cutoff A token representing the precedence of the ...
[ "Add", "parentheses", "to", "the", "LaTeX", "representation", "of", "$node", "if", "needed", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/LaTeXPrinter.php#L355-L389
mossadal/math-parser
src/MathParser/Interpreting/LaTeXPrinter.php
LaTeXPrinter.bracesNeeded
public function bracesNeeded(Node $node) { if ($node instanceof VariableNode || $node instanceof ConstantNode) { return $node->accept($this); } elseif ($node instanceof IntegerNode && $node->getValue() >= 0 && $node->getValue() <= 9) { return $node->accept($this); } e...
php
public function bracesNeeded(Node $node) { if ($node instanceof VariableNode || $node instanceof ConstantNode) { return $node->accept($this); } elseif ($node instanceof IntegerNode && $node->getValue() >= 0 && $node->getValue() <= 9) { return $node->accept($this); } e...
[ "public", "function", "bracesNeeded", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "VariableNode", "||", "$", "node", "instanceof", "ConstantNode", ")", "{", "return", "$", "node", "->", "accept", "(", "$", "this", ")", ";", ...
Add curly braces around the LaTex representation of $node if needed. Nodes representing a single ConstantNode, VariableNode or NumberNodes (0--9) are returned as-is. Other Nodes get curly braces around their LaTeX code. @retval string @param Node $node AST to parse
[ "Add", "curly", "braces", "around", "the", "LaTex", "representation", "of", "$node", "if", "needed", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/LaTeXPrinter.php#L400-L409
mossadal/math-parser
src/MathParser/Interpreting/ASCIIPrinter.php
ASCIIPrinter.visitExpressionNode
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $left = $node->getLeft(); $right = $node->getRight(); switch ($operator) { case '+': $leftValue = $left->accept($this); $rightValue = $this->pare...
php
public function visitExpressionNode(ExpressionNode $node) { $operator = $node->getOperator(); $left = $node->getLeft(); $right = $node->getRight(); switch ($operator) { case '+': $leftValue = $left->accept($this); $rightValue = $this->pare...
[ "public", "function", "visitExpressionNode", "(", "ExpressionNode", "$", "node", ")", "{", "$", "operator", "=", "$", "node", "->", "getOperator", "(", ")", ";", "$", "left", "=", "$", "node", "->", "getLeft", "(", ")", ";", "$", "right", "=", "$", "...
Generate ASCII output code for an ExpressionNode Create a string giving ASCII output representing an ExpressionNode `(x op y)` where `op` is one of `+`, `-`, `*`, `/` or `^` @retval string @param ExpressionNode $node AST to be typeset
[ "Generate", "ASCII", "output", "code", "for", "an", "ExpressionNode" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Interpreting/ASCIIPrinter.php#L69-L112
mossadal/math-parser
src/MathParser/Lexing/Token.php
Token.canFactorsInImplicitMultiplication
public static function canFactorsInImplicitMultiplication($token1, $token2) { if ($token1 === null || $token2 === null) return false; $check1 = ( $token1->type == TokenType::PosInt || $token1->type == TokenType::Integer || $token1->type == TokenType::RealNumber |...
php
public static function canFactorsInImplicitMultiplication($token1, $token2) { if ($token1 === null || $token2 === null) return false; $check1 = ( $token1->type == TokenType::PosInt || $token1->type == TokenType::Integer || $token1->type == TokenType::RealNumber |...
[ "public", "static", "function", "canFactorsInImplicitMultiplication", "(", "$", "token1", ",", "$", "token2", ")", "{", "if", "(", "$", "token1", "===", "null", "||", "$", "token2", "===", "null", ")", "return", "false", ";", "$", "check1", "=", "(", "$"...
Helper function, determining whether a pair of tokens can form an implicit multiplication. Mathematical shorthand writing often leaves out explicit multiplication symbols, writing "2x" instead of "2*x" or "2 \cdot x". The parser accepts implicit multiplication if the first token is a nullary operator or a a closing pa...
[ "Helper", "function", "determining", "whether", "a", "pair", "of", "tokens", "can", "form", "an", "implicit", "multiplication", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Lexing/Token.php#L119-L153
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.normalize
private function normalize() { $gcd = Math::gcd($this->p, $this->q); if ($gcd == 0) throw new DivisionByZeroException(); $this->p = $this->p/$gcd; $this->q = $this->q/$gcd; if ($this->q < 0) { $this->p = -$this->p; $this->q = -$this->q; } ...
php
private function normalize() { $gcd = Math::gcd($this->p, $this->q); if ($gcd == 0) throw new DivisionByZeroException(); $this->p = $this->p/$gcd; $this->q = $this->q/$gcd; if ($this->q < 0) { $this->p = -$this->p; $this->q = -$this->q; } ...
[ "private", "function", "normalize", "(", ")", "{", "$", "gcd", "=", "Math", "::", "gcd", "(", "$", "this", "->", "p", ",", "$", "this", "->", "q", ")", ";", "if", "(", "$", "gcd", "==", "0", ")", "throw", "new", "DivisionByZeroException", "(", ")...
Normalize, i.e. make sure the denominator is positive and that the numerator and denominator have no common factors
[ "Normalize", "i", ".", "e", ".", "make", "sure", "the", "denominator", "is", "positive", "and", "that", "the", "numerator", "and", "denominator", "have", "no", "common", "factors" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L61-L74
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.add
public static function add($x, $y) { $X = static::parse($x); $Y = static::parse($y); $resp = $X->p * $Y->q + $X->q * $Y->p; $resq = $X->q * $Y->q; return new Rational($resp, $resq); }
php
public static function add($x, $y) { $X = static::parse($x); $Y = static::parse($y); $resp = $X->p * $Y->q + $X->q * $Y->p; $resq = $X->q * $Y->q; return new Rational($resp, $resq); }
[ "public", "static", "function", "add", "(", "$", "x", ",", "$", "y", ")", "{", "$", "X", "=", "static", "::", "parse", "(", "$", "x", ")", ";", "$", "Y", "=", "static", "::", "parse", "(", "$", "y", ")", ";", "$", "resp", "=", "$", "X", "...
add two rational numbers Rational::add($x, $y) computes and returns $x+$y @param mixed $x (Rational, or parsable to Rational) @param mixed $y (Rational, or parsable to Rational) @retval Rational
[ "add", "two", "rational", "numbers" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L86-L95
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.div
public static function div($x, $y) { $X = static::parse($x); $Y = static::parse($y); if ($Y->p == 0) throw new DivisionByZeroException(); $resp = $X->p * $Y->q; $resq = $X->q * $Y->p; return new Rational($resp, $resq); }
php
public static function div($x, $y) { $X = static::parse($x); $Y = static::parse($y); if ($Y->p == 0) throw new DivisionByZeroException(); $resp = $X->p * $Y->q; $resq = $X->q * $Y->p; return new Rational($resp, $resq); }
[ "public", "static", "function", "div", "(", "$", "x", ",", "$", "y", ")", "{", "$", "X", "=", "static", "::", "parse", "(", "$", "x", ")", ";", "$", "Y", "=", "static", "::", "parse", "(", "$", "y", ")", ";", "if", "(", "$", "Y", "->", "p...
add two rational numbers Rational::div($x, $y) computes and returns $x/$y @param mixed $x (Rational, or parsable to Rational) @param mixed $y (Rational, or parsable to Rational) @retval Rational
[ "add", "two", "rational", "numbers" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L149-L160
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.signed
public function signed() { if ($this->q == 1) { return sprintf("%+d", $this->p); } return sprintf("%+d/%d", $this->p, $this->q); }
php
public function signed() { if ($this->q == 1) { return sprintf("%+d", $this->p); } return sprintf("%+d/%d", $this->p, $this->q); }
[ "public", "function", "signed", "(", ")", "{", "if", "(", "$", "this", "->", "q", "==", "1", ")", "{", "return", "sprintf", "(", "\"%+d\"", ",", "$", "this", "->", "p", ")", ";", "}", "return", "sprintf", "(", "\"%+d/%d\"", ",", "$", "this", "->"...
convert rational number to string, adding a '+' if the number is positive @retval string
[ "convert", "rational", "number", "to", "string", "adding", "a", "+", "if", "the", "number", "is", "positive" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L167-L175
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.is_nan
public function is_nan() { if ($this->q == 0) return true; return is_nan($this->p) || is_nan($this->q); }
php
public function is_nan() { if ($this->q == 0) return true; return is_nan($this->p) || is_nan($this->q); }
[ "public", "function", "is_nan", "(", ")", "{", "if", "(", "$", "this", "->", "q", "==", "0", ")", "return", "true", ";", "return", "is_nan", "(", "$", "this", "->", "p", ")", "||", "is_nan", "(", "$", "this", "->", "q", ")", ";", "}" ]
test if the rational number is NAN @retval bool
[ "test", "if", "the", "rational", "number", "is", "NAN" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L202-L206
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.parse
public static function parse($value, $normalize=true) { if ($value === '') return null; if ($value === 'NAN') return new Rational(NAN, 1); if ($value === 'INF') return new Rational(INF, 1); if ($value === '-INF') return new Rational(-INF, 1); $data = $value; $number...
php
public static function parse($value, $normalize=true) { if ($value === '') return null; if ($value === 'NAN') return new Rational(NAN, 1); if ($value === 'INF') return new Rational(INF, 1); if ($value === '-INF') return new Rational(-INF, 1); $data = $value; $number...
[ "public", "static", "function", "parse", "(", "$", "value", ",", "$", "normalize", "=", "true", ")", "{", "if", "(", "$", "value", "===", "''", ")", "return", "null", ";", "if", "(", "$", "value", "===", "'NAN'", ")", "return", "new", "Rational", "...
Convert $value to Rational @param $value mixed @throws SyntaxErrorException @retval Rational
[ "Convert", "$value", "to", "Rational" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L215-L242
mossadal/math-parser
src/MathParser/Extensions/Rational.php
Rational.fromFloat
public static function fromFloat($float, $tolerance=1e-7) { if (is_string($float) && preg_match('~^\-?\d+([,|.]\d+)?$~', $float)) { $float = floatval(str_replace(',','.',$float)); } if ($float == 0.0) { return new Rational(0,1); } $negative = ($float ...
php
public static function fromFloat($float, $tolerance=1e-7) { if (is_string($float) && preg_match('~^\-?\d+([,|.]\d+)?$~', $float)) { $float = floatval(str_replace(',','.',$float)); } if ($float == 0.0) { return new Rational(0,1); } $negative = ($float ...
[ "public", "static", "function", "fromFloat", "(", "$", "float", ",", "$", "tolerance", "=", "1e-7", ")", "{", "if", "(", "is_string", "(", "$", "float", ")", "&&", "preg_match", "(", "'~^\\-?\\d+([,|.]\\d+)?$~'", ",", "$", "float", ")", ")", "{", "$", ...
convert float to Rational Convert float to a continued fraction, with prescribed accuracy @param string|float $float @param float $tolerance @retval Rational
[ "convert", "float", "to", "Rational" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Extensions/Rational.php#L253-L287
mossadal/math-parser
src/MathParser/Parsing/Nodes/ConstantNode.php
ConstantNode.compareTo
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof ConstantNode)) { return false; } return $this->getName() == $other->getName(); }
php
public function compareTo($other) { if ($other === null) { return false; } if (!($other instanceof ConstantNode)) { return false; } return $this->getName() == $other->getName(); }
[ "public", "function", "compareTo", "(", "$", "other", ")", "{", "if", "(", "$", "other", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "(", "$", "other", "instanceof", "ConstantNode", ")", ")", "{", "return", "false", ";", "...
Implementing the compareTo abstract method.
[ "Implementing", "the", "compareTo", "abstract", "method", "." ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/ConstantNode.php#L61-L71
mossadal/math-parser
src/MathParser/Parsing/Nodes/Factories/AdditionNodeFactory.php
AdditionNodeFactory.makeNode
public function makeNode($leftOperand, $rightOperand) { $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); $node = $this->numericTerms($leftOperand, $rightOperand); if ($node) return $node; return new ExpressionNode($leftOperand, '...
php
public function makeNode($leftOperand, $rightOperand) { $leftOperand = $this->sanitize($leftOperand); $rightOperand = $this->sanitize($rightOperand); $node = $this->numericTerms($leftOperand, $rightOperand); if ($node) return $node; return new ExpressionNode($leftOperand, '...
[ "public", "function", "makeNode", "(", "$", "leftOperand", ",", "$", "rightOperand", ")", "{", "$", "leftOperand", "=", "$", "this", "->", "sanitize", "(", "$", "leftOperand", ")", ";", "$", "rightOperand", "=", "$", "this", "->", "sanitize", "(", "$", ...
Create a Node representing 'leftOperand + rightOperand' Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing 'leftOperand + rightOperand'. ### Simplification rules: - To simplify the use of the function, convert integer or float params to NumberNodes - If $leftO...
[ "Create", "a", "Node", "representing", "leftOperand", "+", "rightOperand" ]
train
https://github.com/mossadal/math-parser/blob/1ef8217fe48c8a02fdf4ca6da4fa0561732981fb/src/MathParser/Parsing/Nodes/Factories/AdditionNodeFactory.php#L50-L59
TheDMSGroup/mautic-contact-client
Model/Attribution.php
Attribution.applyAttribution
public function applyAttribution() { $update = false; $originalAttribution = $this->contact->getFieldValue('attribution'); $originalAttribution = !empty($originalAttribution) ? $originalAttribution : 0; $attributionChange = 0; if ($this->payloadModel) { ...
php
public function applyAttribution() { $update = false; $originalAttribution = $this->contact->getFieldValue('attribution'); $originalAttribution = !empty($originalAttribution) ? $originalAttribution : 0; $attributionChange = 0; if ($this->payloadModel) { ...
[ "public", "function", "applyAttribution", "(", ")", "{", "$", "update", "=", "false", ";", "$", "originalAttribution", "=", "$", "this", "->", "contact", "->", "getFieldValue", "(", "'attribution'", ")", ";", "$", "originalAttribution", "=", "!", "empty", "(...
Apply attribution to the current contact based on payload and settings of the Contact Client. This assumes the Payload was successfully delivered (valid = true). @return bool @throws \Exception
[ "Apply", "attribution", "to", "the", "current", "contact", "based", "on", "payload", "and", "settings", "of", "the", "Contact", "Client", ".", "This", "assumes", "the", "Payload", "was", "successfully", "delivered", "(", "valid", "=", "true", ")", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Attribution.php#L57-L127
TheDMSGroup/mautic-contact-client
Controller/FilesController.php
FilesController.fileAction
public function fileAction($objectId, $fileId) { if (empty($objectId) || empty($fileId)) { return $this->accessDenied(); } $contactClient = $this->checkContactClientAccess($objectId, 'view'); if ($contactClient instanceof Response) { return $contactClient; ...
php
public function fileAction($objectId, $fileId) { if (empty($objectId) || empty($fileId)) { return $this->accessDenied(); } $contactClient = $this->checkContactClientAccess($objectId, 'view'); if ($contactClient instanceof Response) { return $contactClient; ...
[ "public", "function", "fileAction", "(", "$", "objectId", ",", "$", "fileId", ")", "{", "if", "(", "empty", "(", "$", "objectId", ")", "||", "empty", "(", "$", "fileId", ")", ")", "{", "return", "$", "this", "->", "accessDenied", "(", ")", ";", "}"...
Downloads a file securely. @param null $contactClientId @param null $fileId @return array|\MauticPlugin\MauticContactClientBundle\Entity\ContactClient|BinaryFileResponse|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse @throws \Exception
[ "Downloads", "a", "file", "securely", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/FilesController.php#L75-L100
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.addEvent
public function addEvent(array $data) { if ($this->countOnly) { // BC support for old format if ($this->groupUnit && $this->chartQuery) { $countData = [ [ 'date' => $data['timestamp'], 'count' => 1, ...
php
public function addEvent(array $data) { if ($this->countOnly) { // BC support for old format if ($this->groupUnit && $this->chartQuery) { $countData = [ [ 'date' => $data['timestamp'], 'count' => 1, ...
[ "public", "function", "addEvent", "(", "array", "$", "data", ")", "{", "if", "(", "$", "this", "->", "countOnly", ")", "{", "// BC support for old format", "if", "(", "$", "this", "->", "groupUnit", "&&", "$", "this", "->", "chartQuery", ")", "{", "$", ...
Add an event to the container. The data should be an associative array with the following data: 'event' => string The event name 'timestamp' => \DateTime The timestamp of the event 'extra' => array An optional array of extra data for the event @param array $data Data array for the table
[ "Add", "an", "event", "to", "the", "container", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L187-L253
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.addToCounter
public function addToCounter($eventType, $count) { if (!isset($this->totalEvents[$eventType])) { $this->totalEvents[$eventType] = 0; } if (is_array($count)) { if (isset($count['total'])) { $this->totalEvents[$eventType] += $count['total']; ...
php
public function addToCounter($eventType, $count) { if (!isset($this->totalEvents[$eventType])) { $this->totalEvents[$eventType] = 0; } if (is_array($count)) { if (isset($count['total'])) { $this->totalEvents[$eventType] += $count['total']; ...
[ "public", "function", "addToCounter", "(", "$", "eventType", ",", "$", "count", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "totalEvents", "[", "$", "eventType", "]", ")", ")", "{", "$", "this", "->", "totalEvents", "[", "$", "eventTyp...
Add to the event counters. @param int|array $count
[ "Add", "to", "the", "event", "counters", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L260-L284
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.getEvents
public function getEvents() { if (empty($this->events)) { return []; } $events = call_user_func_array('array_merge', $this->events); foreach ($events as &$e) { if (!$e['timestamp'] instanceof \DateTime) { $dt = new DateTimeHelper(...
php
public function getEvents() { if (empty($this->events)) { return []; } $events = call_user_func_array('array_merge', $this->events); foreach ($events as &$e) { if (!$e['timestamp'] instanceof \DateTime) { $dt = new DateTimeHelper(...
[ "public", "function", "getEvents", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "events", ")", ")", "{", "return", "[", "]", ";", "}", "$", "events", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "this", "->", "events", "...
Fetch the events. @return array Events sorted by timestamp with most recent event first
[ "Fetch", "the", "events", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L353-L421
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.getEventLimit
public function getEventLimit() { return [ 'contactClientId' => ($this->contactClient instanceof ContactClient) ? $this->contactClient->getId() : null, 'limit' => $this->limit, 'start' => (1 >= $this->page) ? 0 : ($this->page - 1) * $this->limit, ...
php
public function getEventLimit() { return [ 'contactClientId' => ($this->contactClient instanceof ContactClient) ? $this->contactClient->getId() : null, 'limit' => $this->limit, 'start' => (1 >= $this->page) ? 0 : ($this->page - 1) * $this->limit, ...
[ "public", "function", "getEventLimit", "(", ")", "{", "return", "[", "'contactClientId'", "=>", "(", "$", "this", "->", "contactClient", "instanceof", "ContactClient", ")", "?", "$", "this", "->", "contactClient", "->", "getId", "(", ")", ":", "null", ",", ...
Fetch start/limit for queries. @return array
[ "Fetch", "start", "/", "limit", "for", "queries", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L499-L506
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.getEventCounter
public function getEventCounter() { // BC support for old formats foreach ($this->events as $type => $events) { if (!isset($this->totalEvents[$type])) { $this->totalEvents[$type] = count($events); } } $counter = [ 'total' => array_...
php
public function getEventCounter() { // BC support for old formats foreach ($this->events as $type => $events) { if (!isset($this->totalEvents[$type])) { $this->totalEvents[$type] = count($events); } } $counter = [ 'total' => array_...
[ "public", "function", "getEventCounter", "(", ")", "{", "// BC support for old formats", "foreach", "(", "$", "this", "->", "events", "as", "$", "type", "=>", "$", "events", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "totalEvents", "[", "...
Get total number of events for pagination.
[ "Get", "total", "number", "of", "events", "for", "pagination", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L566-L584
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.setCountOnly
public function setCountOnly( \DateTime $dateFrom, \DateTime $dateTo, $groupUnit = '', ChartQuery $chartQuery = null ) { $this->countOnly = true; $this->dateFrom = $dateFrom; $this->dateTo = $dateTo; $this->groupUnit = $groupUnit; $this...
php
public function setCountOnly( \DateTime $dateFrom, \DateTime $dateTo, $groupUnit = '', ChartQuery $chartQuery = null ) { $this->countOnly = true; $this->dateFrom = $dateFrom; $this->dateTo = $dateTo; $this->groupUnit = $groupUnit; $this...
[ "public", "function", "setCountOnly", "(", "\\", "DateTime", "$", "dateFrom", ",", "\\", "DateTime", "$", "dateTo", ",", "$", "groupUnit", "=", "''", ",", "ChartQuery", "$", "chartQuery", "=", "null", ")", "{", "$", "this", "->", "countOnly", "=", "true"...
Calculate engagement counts only. @param \DateTime $dateFrom @param \DateTime $dateTo @param string $groupUnit @param ChartQuery|null $chartQuery
[ "Calculate", "engagement", "counts", "only", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L605-L616
TheDMSGroup/mautic-contact-client
Event/ContactClientTimelineEvent.php
ContactClientTimelineEvent.addSerializerGroup
public function addSerializerGroup($group) { if (is_array($group)) { $this->serializerGroups = array_merge( $this->serializerGroups, $group ); } else { $this->serializerGroups[$group] = $group; } }
php
public function addSerializerGroup($group) { if (is_array($group)) { $this->serializerGroups = array_merge( $this->serializerGroups, $group ); } else { $this->serializerGroups[$group] = $group; } }
[ "public", "function", "addSerializerGroup", "(", "$", "group", ")", "{", "if", "(", "is_array", "(", "$", "group", ")", ")", "{", "$", "this", "->", "serializerGroups", "=", "array_merge", "(", "$", "this", "->", "serializerGroups", ",", "$", "group", ")...
Add a serializer group for API formatting. @param $group
[ "Add", "a", "serializer", "group", "for", "API", "formatting", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Event/ContactClientTimelineEvent.php#L633-L643
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.addHelper
private function addHelper($type) { switch ($type) { case 'number': if (!$this->engine->hasHelper('lpad')) { $this->engine->addHelper( 'lpad', [ '2' => function ($value) { ...
php
private function addHelper($type) { switch ($type) { case 'number': if (!$this->engine->hasHelper('lpad')) { $this->engine->addHelper( 'lpad', [ '2' => function ($value) { ...
[ "private", "function", "addHelper", "(", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'number'", ":", "if", "(", "!", "$", "this", "->", "engine", "->", "hasHelper", "(", "'lpad'", ")", ")", "{", "$", "this", "->", "engine"...
Add token helpers/filters to the engine. @param $type
[ "Add", "token", "helpers", "/", "filters", "to", "the", "engine", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L245-L729
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.getTokens
public function getTokens($string) { $tokens = []; $scanResults = $this->engine->getTokenizer()->scan($string); foreach ($scanResults as $scanResult) { if ( isset($scanResult['type']) && isset($scanResult['name']) && \Mustache...
php
public function getTokens($string) { $tokens = []; $scanResults = $this->engine->getTokenizer()->scan($string); foreach ($scanResults as $scanResult) { if ( isset($scanResult['type']) && isset($scanResult['name']) && \Mustache...
[ "public", "function", "getTokens", "(", "$", "string", ")", "{", "$", "tokens", "=", "[", "]", ";", "$", "scanResults", "=", "$", "this", "->", "engine", "->", "getTokenizer", "(", ")", "->", "scan", "(", "$", "string", ")", ";", "foreach", "(", "$...
Scan a string for tokens using the same engine. @param $string @return array a unique list of all the raw mustache tags found in the string
[ "Scan", "a", "string", "for", "tokens", "using", "the", "same", "engine", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L738-L754
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.getFormats
public function getFormats() { return [ 'date' => $this->getDateFormatHelper()->getFormatsDate(), 'datetime' => $this->getDateFormatHelper()->getFormatsDateTime(), 'time' => $this->getDateFormatHelper()->getFormatsTime(), 'number' => $this->formatNum...
php
public function getFormats() { return [ 'date' => $this->getDateFormatHelper()->getFormatsDate(), 'datetime' => $this->getDateFormatHelper()->getFormatsDateTime(), 'time' => $this->getDateFormatHelper()->getFormatsTime(), 'number' => $this->formatNum...
[ "public", "function", "getFormats", "(", ")", "{", "return", "[", "'date'", "=>", "$", "this", "->", "getDateFormatHelper", "(", ")", "->", "getFormatsDate", "(", ")", ",", "'datetime'", "=>", "$", "this", "->", "getDateFormatHelper", "(", ")", "->", "getF...
Outputs an array of formats by field type for the front-end tokenization. @return array
[ "Outputs", "an", "array", "of", "formats", "by", "field", "type", "for", "the", "front", "-", "end", "tokenization", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L761-L775
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.newSession
public function newSession( ContactClient $contactClient = null, Contact $contact = null, $payload = [], $campaign = null, $event = [] ) { $this->context = []; $this->renderCache = []; $this->setContactClient($contactClient); $this->addCont...
php
public function newSession( ContactClient $contactClient = null, Contact $contact = null, $payload = [], $campaign = null, $event = [] ) { $this->context = []; $this->renderCache = []; $this->setContactClient($contactClient); $this->addCont...
[ "public", "function", "newSession", "(", "ContactClient", "$", "contactClient", "=", "null", ",", "Contact", "$", "contact", "=", "null", ",", "$", "payload", "=", "[", "]", ",", "$", "campaign", "=", "null", ",", "$", "event", "=", "[", "]", ")", "{...
@param ContactClient|null $contactClient @param Contact|null $contact @param array $payload @param null $campaign @param array $event @return $this
[ "@param", "ContactClient|null", "$contactClient", "@param", "Contact|null", "$contact", "@param", "array", "$payload", "@param", "null", "$campaign", "@param", "array", "$event" ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L802-L818
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.setContactClient
public function setContactClient(ContactClient $contactClient = null) { if ($contactClient && $contactClient !== $this->contactClient) { $this->contactClient = $contactClient; // Set the timezones for date/time conversion. $tza = $this->coreParametersHel...
php
public function setContactClient(ContactClient $contactClient = null) { if ($contactClient && $contactClient !== $this->contactClient) { $this->contactClient = $contactClient; // Set the timezones for date/time conversion. $tza = $this->coreParametersHel...
[ "public", "function", "setContactClient", "(", "ContactClient", "$", "contactClient", "=", "null", ")", "{", "if", "(", "$", "contactClient", "&&", "$", "contactClient", "!==", "$", "this", "->", "contactClient", ")", "{", "$", "this", "->", "contactClient", ...
@param ContactClient $contactClient @return $this
[ "@param", "ContactClient", "$contactClient" ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L825-L843
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.addContextPayload
public function addContextPayload($payload = [], $operationId = null, $responseActual = []) { if (!$payload) { return $this; } $payload = json_decode(json_encode($payload), true); if ($payload === $this->previousPayload && !$responseActual) { // The payload is...
php
public function addContextPayload($payload = [], $operationId = null, $responseActual = []) { if (!$payload) { return $this; } $payload = json_decode(json_encode($payload), true); if ($payload === $this->previousPayload && !$responseActual) { // The payload is...
[ "public", "function", "addContextPayload", "(", "$", "payload", "=", "[", "]", ",", "$", "operationId", "=", "null", ",", "$", "responseActual", "=", "[", "]", ")", "{", "if", "(", "!", "$", "payload", ")", "{", "return", "$", "this", ";", "}", "$"...
Simplify the payload for tokens, including actual response data when possible. @param array $payload @param null $operationId @param array $responseActual @return $this
[ "Simplify", "the", "payload", "for", "tokens", "including", "actual", "response", "data", "when", "possible", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L854-L933
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.findPivotDataTokens
private function findPivotDataTokens($string) { if ( !$this->needsDeviceData && 1 === preg_match('/{{\s?device\..*\s?}}/', $string) ) { $this->needsDeviceData = true; } if ( !$this->needsUtmData && 1 === preg_match('/{{\s?ut...
php
private function findPivotDataTokens($string) { if ( !$this->needsDeviceData && 1 === preg_match('/{{\s?device\..*\s?}}/', $string) ) { $this->needsDeviceData = true; } if ( !$this->needsUtmData && 1 === preg_match('/{{\s?ut...
[ "private", "function", "findPivotDataTokens", "(", "$", "string", ")", "{", "if", "(", "!", "$", "this", "->", "needsDeviceData", "&&", "1", "===", "preg_match", "(", "'/{{\\s?device\\..*\\s?}}/'", ",", "$", "string", ")", ")", "{", "$", "this", "->", "nee...
Check for the need for device data to keep queries low later. @param $string
[ "Check", "for", "the", "need", "for", "device", "data", "to", "keep", "queries", "low", "later", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L940-L960
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.addContextContact
public function addContextContact(Contact $contact = null) { if (!$contact) { return $this; } $context = []; $conType = []; // Append contact ID. $contactId = (int) $contact->getId(); $context['id'] = isset($contactId) ? $contactId : null; ...
php
public function addContextContact(Contact $contact = null) { if (!$contact) { return $this; } $context = []; $conType = []; // Append contact ID. $contactId = (int) $contact->getId(); $context['id'] = isset($contactId) ? $contactId : null; ...
[ "public", "function", "addContextContact", "(", "Contact", "$", "contact", "=", "null", ")", "{", "if", "(", "!", "$", "contact", ")", "{", "return", "$", "this", ";", "}", "$", "context", "=", "[", "]", ";", "$", "conType", "=", "[", "]", ";", "...
Given a Contact, flatten the field values a bit into a more user friendly list of token possibilities. @param Contact|null $contact @return $this
[ "Given", "a", "Contact", "flatten", "the", "field", "values", "a", "bit", "into", "a", "more", "user", "friendly", "list", "of", "token", "possibilities", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L969-L1160
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.addContextEvent
public function addContextEvent($event = []) { $contactId = isset($this->context['id']) ? $this->context['id'] : 0; $this->context['event']['id'] = !empty($event['id']) ? (int) $event['id'] : null; $this->context['event']['name'] = !empty($event['name']) ? $event['n...
php
public function addContextEvent($event = []) { $contactId = isset($this->context['id']) ? $this->context['id'] : 0; $this->context['event']['id'] = !empty($event['id']) ? (int) $event['id'] : null; $this->context['event']['name'] = !empty($event['name']) ? $event['n...
[ "public", "function", "addContextEvent", "(", "$", "event", "=", "[", "]", ")", "{", "$", "contactId", "=", "isset", "(", "$", "this", "->", "context", "[", "'id'", "]", ")", "?", "$", "this", "->", "context", "[", "'id'", "]", ":", "0", ";", "$"...
Take an event array and use it to enhance the context for later dispositional callback. Campaign context should be added before this, as it is used for the token. @param array $event
[ "Take", "an", "event", "array", "and", "use", "it", "to", "enhance", "the", "context", "for", "later", "dispositional", "callback", ".", "Campaign", "context", "should", "be", "added", "before", "this", "as", "it", "is", "used", "for", "the", "token", "." ...
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1186-L1201
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.eventTokenEncode
private function eventTokenEncode($values) { list($campaignId, $eventId, $contactId) = $values; $campaignIdString = $this->baseEncode((int) $campaignId); $eventIdString = $this->baseEncode((int) $eventId); $contactIdString ...
php
private function eventTokenEncode($values) { list($campaignId, $eventId, $contactId) = $values; $campaignIdString = $this->baseEncode((int) $campaignId); $eventIdString = $this->baseEncode((int) $eventId); $contactIdString ...
[ "private", "function", "eventTokenEncode", "(", "$", "values", ")", "{", "list", "(", "$", "campaignId", ",", "$", "eventId", ",", "$", "contactId", ")", "=", "$", "values", ";", "$", "campaignIdString", "=", "$", "this", "->", "baseEncode", "(", "(", ...
Encode Campaign ID, Event ID, and Contact ID into a short base62 string. Zeros are used as delimiters reducing the subsequent integers to base61. @param $values @return string
[ "Encode", "Campaign", "ID", "Event", "ID", "and", "Contact", "ID", "into", "a", "short", "base62", "string", ".", "Zeros", "are", "used", "as", "delimiters", "reducing", "the", "subsequent", "integers", "to", "base61", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1211-L1219
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.baseEncode
private function baseEncode($integer) { $b = 61; $base = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $r = $integer % $b; $result = $base[$r]; $q = floor($integer / $b); while ($q) { $r = $q % $b; $q ...
php
private function baseEncode($integer) { $b = 61; $base = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $r = $integer % $b; $result = $base[$r]; $q = floor($integer / $b); while ($q) { $r = $q % $b; $q ...
[ "private", "function", "baseEncode", "(", "$", "integer", ")", "{", "$", "b", "=", "61", ";", "$", "base", "=", "'123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'", ";", "$", "r", "=", "$", "integer", "%", "$", "b", ";", "$", "result", "=", "...
@param $integer @param int $b @return string
[ "@param", "$integer", "@param", "int", "$b" ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1227-L1241
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.addContext
public function addContext($context = []) { if (!$context || empty($context)) { return $this; } $this->nestContext($context); $this->sanitizeContext($context); $this->context = array_merge($this->context, $context); return $this; }
php
public function addContext($context = []) { if (!$context || empty($context)) { return $this; } $this->nestContext($context); $this->sanitizeContext($context); $this->context = array_merge($this->context, $context); return $this; }
[ "public", "function", "addContext", "(", "$", "context", "=", "[", "]", ")", "{", "if", "(", "!", "$", "context", "||", "empty", "(", "$", "context", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "nestContext", "(", "$", "con...
@param array $context @return $this
[ "@param", "array", "$context" ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1248-L1258
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.nestContext
private function nestContext(&$context) { foreach ($context as $key => $value) { $dot = strpos($key, '.'); if ($dot && $dot !== strlen($key) - 1) { $currentContext = &$context; foreach (explode('.', $key) as $k) { if (!isset($curren...
php
private function nestContext(&$context) { foreach ($context as $key => $value) { $dot = strpos($key, '.'); if ($dot && $dot !== strlen($key) - 1) { $currentContext = &$context; foreach (explode('.', $key) as $k) { if (!isset($curren...
[ "private", "function", "nestContext", "(", "&", "$", "context", ")", "{", "foreach", "(", "$", "context", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "dot", "=", "strpos", "(", "$", "key", ",", "'.'", ")", ";", "if", "(", "$", "dot", "...
Nest keys containing dots as Mustache contextual arrays. ex. ['utm.source' => 'value'] becomes ['utm' => ['source' => 'value']]. @param $context @return mixed
[ "Nest", "keys", "containing", "dots", "as", "Mustache", "contextual", "arrays", ".", "ex", ".", "[", "utm", ".", "source", "=", ">", "value", "]", "becomes", "[", "utm", "=", ">", "[", "source", "=", ">", "value", "]]", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1268-L1286
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.render
public function render($template = '') { $result = $template; if (is_array($template) || is_object($template)) { // Recursively go down into an object/array to tokenize. foreach ($result as &$val) { $val = $this->render($val); } } elseif ( ...
php
public function render($template = '') { $result = $template; if (is_array($template) || is_object($template)) { // Recursively go down into an object/array to tokenize. foreach ($result as &$val) { $val = $this->render($val); } } elseif ( ...
[ "public", "function", "render", "(", "$", "template", "=", "''", ")", "{", "$", "result", "=", "$", "template", ";", "if", "(", "is_array", "(", "$", "template", ")", "||", "is_object", "(", "$", "template", ")", ")", "{", "// Recursively go down into an...
Replace Tokens in a simple string using an array for context. @param string|array|object $template @return string|array|object
[ "Replace", "Tokens", "in", "a", "simple", "string", "using", "an", "array", "for", "context", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1295-L1326
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.getContext
public function getContext($flattened = false) { $result = []; if ($flattened) { $this->flattenArray($this->context, $result); } else { $result = $this->context; } return $result; }
php
public function getContext($flattened = false) { $result = []; if ($flattened) { $this->flattenArray($this->context, $result); } else { $result = $this->context; } return $result; }
[ "public", "function", "getContext", "(", "$", "flattened", "=", "false", ")", "{", "$", "result", "=", "[", "]", ";", "if", "(", "$", "flattened", ")", "{", "$", "this", "->", "flattenArray", "(", "$", "this", "->", "context", ",", "$", "result", "...
@param bool $flattened @return array
[ "@param", "bool", "$flattened" ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1333-L1343
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.getContextLabeled
public function getContextLabeled($sort = true) { $result = []; $labels = $this->describe($this->context); $this->flattenArray($labels, $result); $result['file_count'] = 'File: Number of contacts in this file'; $result['file_test'] = 'File: Inserts ".test" if te...
php
public function getContextLabeled($sort = true) { $result = []; $labels = $this->describe($this->context); $this->flattenArray($labels, $result); $result['file_count'] = 'File: Number of contacts in this file'; $result['file_test'] = 'File: Inserts ".test" if te...
[ "public", "function", "getContextLabeled", "(", "$", "sort", "=", "true", ")", "{", "$", "result", "=", "[", "]", ";", "$", "labels", "=", "$", "this", "->", "describe", "(", "$", "this", "->", "context", ")", ";", "$", "this", "->", "flattenArray", ...
Get the context array labels instead of values for use in token suggestions. @param bool $sort @return array
[ "Get", "the", "context", "array", "labels", "instead", "of", "values", "for", "use", "in", "token", "suggestions", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1382-L1401
TheDMSGroup/mautic-contact-client
Helper/TokenHelper.php
TokenHelper.describe
private function describe($array = [], $keys = '', $sort = true, $payload = false) { foreach ($array as $key => &$value) { if (is_array($value)) { if (0 === count($value)) { // Currently such groups are undocumented, so labels are not needed. ...
php
private function describe($array = [], $keys = '', $sort = true, $payload = false) { foreach ($array as $key => &$value) { if (is_array($value)) { if (0 === count($value)) { // Currently such groups are undocumented, so labels are not needed. ...
[ "private", "function", "describe", "(", "$", "array", "=", "[", "]", ",", "$", "keys", "=", "''", ",", "$", "sort", "=", "true", ",", "$", "payload", "=", "false", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "&", "$", "value...
Given a token array, set the values to the labels for the context if possible. @param array $array @param string $keys @param bool $sort @param bool $payload @return array
[ "Given", "a", "token", "array", "set", "the", "values", "to", "the", "labels", "for", "the", "context", "if", "possible", "." ]
train
https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/TokenHelper.php#L1413-L1452