for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the STL package.
*
* (c) Grosan Flaviu Gheorghe <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace php3d\stl;
/**
* Class STLSplit. Extracts separate 3D objects as STL objects.
* @package php3d\stl
class STLSplit {
* @var STL
private $stl;
* @return STL
public function getStl(): STL
{
return $this->stl;
}
* @param STL $stl
* @return STLSplit
private function setStl(STL $stl): STLSplit
$this->stl = $stl;
return $this;
* STLSplit constructor.
public function __construct(STL $stl)
$this->setStl($stl);
* Splits an STL object into 3, and returns the new 3D objects in an array of STL files.
* @return array
public function split() : array
$stlArray = $this->getStl()->toArray();
$facets = $stlArray["facets"];
$objArray = array();
$vertex = $facets[0];
unset($facets[0]);
$current = 0;
$objArray[$current] = array($vertex);
while (count($facets) != 0) {
$this->findNeighbour(
$vertex,
$objArray[$current],
$facets
);
$vertex = array_pop($facets);
$current++;
if ($vertex) {
$stlObjects = array();
foreach ($objArray as $key => $object) {
$stlObjects[] = STL::fromArray(array(
"name" => $this->getStl()->getSolidName() . $key,
"facets" => $object
));
return $stlObjects;
* Finds the neighbouring facets of a facet.
* @param array $facet
* @param array $object
* @param array $facets
private function findNeighbour(array $facet, array &$object, array &$facets)
foreach ($facets as $key => $_facet) {
for ($i = 0; $i < 3; $i++) {
$i++;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
return false
if (in_array($_facet["vertex"][$i], $facet["vertex"])) {
unset($facets[$key]);
$object[] = $_facet;
$_facet,
$object,
continue 2;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.