Saves the service and types php code to file

@param PhpClass $service
@param array $types
723
public function save(PhpClass $service, array $types)
    {
        $this->setOutputDirectory();

        $this->saveClassToFile($service);
        foreach ($types as $type) {
            $this->saveClassToFile($type);
        }

        $classes = array_merge(array($service), $types);
        $this->saveAutoloader($service->getIdentifier(), $classes);
    }
581280
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->currentFile !== $phpcsFile->getFilename()) {
            $this->classCount  = 0;
            $this->currentFile = $phpcsFile->getFilename();
        }

        $this->classCount++;

        if ($this->classCount > 1) {
            $phpcsFile->addError(
                'Multiple classes defined in a single file',
                $stackPtr,
                'Invalid'
            );
        }

        return;
    }
1178980
public static void saveClass(Path rootDir, String packageName, String className, TypeSpec type)
      throws IOException {

    List<String> packagePath = Splitter.on('.').splitToList(packageName);
    Path classPath = Paths.get(rootDir.toString(), packagePath.toArray(EMPTY));
    Path outputFile = classPath.resolve(className + ".java");

    JavaFile javaFile = JavaFile.builder(packageName, type)
        .addFileComment("\n\nAUTO-GENERATED CLASS - DO NOT EDIT\n\n")
        // TODO: build timestamp and version info
        .build();

    System.out.println("saving " + outputFile);
    Files.createParentDirs(outputFile.toFile());
    CharSink sink = Files.asCharSink(outputFile.toFile(), Charsets.UTF_8);
    sink.write(javaFile.toString());
  }
763379
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $this->currentFile = $phpcsFile;

        $tokens = $phpcsFile->getTokens();
        $type = strtolower($tokens[$stackPtr]['content']);
        $errorData = array($type);

        $find = PHP_CodeSniffer_Tokens::$methodPrefixes;
        $find[] = T_WHITESPACE;

        $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
        if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
            && $tokens[$commentEnd]['code'] !== T_COMMENT
        ) {
            $fix = $phpcsFile->addFixableError('Missing class doc comment', $stackPtr, 'Missing');

            if (true === $fix) {
                $className = $tokens[$stackPtr + 2]['content'];

                $packageName = $this->findNamespace($tokens);

                $comment =
                    sprintf(
                        "/**" . $phpcsFile->eolChar .
                        " * Class %s" . $phpcsFile->eolChar .
                        ($packageName ? sprintf(" * @package %s" . $phpcsFile->eolChar, $packageName) : '') .
                        " */" . $phpcsFile->eolChar,
                        $className
                    );

                $phpcsFile->fixer->addContentBefore($stackPtr, $comment);
            }

            $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'no');

            return;
        } else {
            $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'yes');
        }

        // Try and determine if this is a file comment instead of a class comment.
        // We assume that if this is the first comment after the open PHP tag, then
        // it is most likely a file comment instead of a class comment.
        if ($tokens[$commentEnd]['code'] === T_DOC_COMMENT_CLOSE_TAG) {
            $start = ($tokens[$commentEnd]['comment_opener'] - 1);
        } else {
            $start = $phpcsFile->findPrevious(T_COMMENT, ($commentEnd - 1), null, true);
        }

        $prev = $phpcsFile->findPrevious(T_WHITESPACE, $start, null, true);
        if ($tokens[$prev]['code'] === T_OPEN_TAG) {
            $prevOpen = $phpcsFile->findPrevious(T_OPEN_TAG, ($prev - 1));
            if ($prevOpen === false) {
                // This is a comment directly after the first open tag,
                // so probably a file comment.
                $phpcsFile->addError('Missing class doc comment', $stackPtr, 'Missing');

                return;
            }
        }

        if ($tokens[$commentEnd]['code'] === T_COMMENT) {
            $phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle');

            return;
        }

        // Check each tag.
        $this->processTags($phpcsFile, $stackPtr, $tokens[$commentEnd]['comment_opener']);

    }
323362
public static void writeClasses(ObjectOutput out, Class<?>[] types)
            throws java.io.IOException {
        int i;

        if (types.length > Byte.MAX_VALUE) {
            throw new RuntimeException("to many dimensions");
        }
        out.writeByte((byte) types.length);
        for (i = 0; i < types.length; i++) {
            write(out, types[i]);
        }
    }
721195
public function afterCompile(ClassType $class): void
	{
		$config = $this->config;

		if ($config->debug === true) {
			$initialize = $class->getMethod('initialize');
			$initialize->addBody(
				'$this->getService(?)->addPanel($this->getService(?));',
				['tracy.bar', $this->prefix('panel')]
			);
		}
	}
490546
private function checkFormClass($type, $classes)
    {
        return array_filter($classes, function ($subclass) use ($type) {
            return is_a($type, $subclass, true);
        });
    }
1024496
public static function registerType($name, $class, $phpTypeName)
    {
        if (isset(static::$typesMap[$name])) {
            throw new BadArgumentException('Cannot register new type with name ":name" because it already registered', [
                'name' => $name,
            ]);
        }
        
        static::overrideType($name, $class, $phpTypeName);
    }
562782
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // In case we have more than one class/interface/trait
        // per file, we want to reset at the start of each.
        if ($tokens[$stackPtr]['code'] !== T_FUNCTION) {
            $this->lastMethodName = null;
            return;
        }

        // We only care about class methods, so ignore global functions (level 0).
        if ($tokens[$stackPtr]['level'] === 1) {
            $methodName = $phpcsFile->getDeclarationName($stackPtr);
            if ($this->lastMethodName !== null && $methodName <= $this->lastMethodName) {
                $phpcsFile->addError('Method "%s" is not in alphabetical order.', $stackPtr, 'OutOfOrder', [$methodName]);
            }

            $this->lastMethodName = $methodName;
        }

    }
434438
public function processFileClasses(array $classes, string $file)
    {
        foreach ($classes as $name => $class) {
            if (is_null($class['docblock'])) {
                $this->errors[] = [
                    'type' => 'class',
                    'file' => $file,
                    'class' => $name,
                    'line' => $class['line'],
                ];
            }
        }
    }
699764
protected function save($entities)
    {
        if (!is_array($entities)) {
            $entities = [$entities];
        }

        foreach ($entities as $entity) {
            $entityClass = get_class($entity);
            $entityManager = $this
                ->get('base.object_manager_provider')
                ->getObjectManagerByEntityNamespace($entityClass);
            $entityManager->persist($entity);
            $entityManager->flush($entity);
        }
    }
763674
public function buildService()
  {
    require_once($this->classFile);
    $wsdl = $this->generateWsdl();

    if (isset($_GET['wsdl'])) {
      print $wsdl;
    } else {
      $file = 'data://text/plain;base64,'. base64_encode($wsdl);
      $server = new \SoapServer($file);
      $server->setClass($this->className);
      $functions = get_class_methods($this->className);
      foreach ($functions as $function) {
        $server->addFunction($function);
      }
      $server->handle();
    }
  }
514003
private function loadServices(ContainerBuilder $container, array $services, array $types)
    {
        $manager = $container->getDefinition('tree_house.keystone.service_manager');
        $manager->addMethodCall('setTypes', [$types]);

        foreach ($services as $name => $serviceConfig) {
            if (!in_array($serviceConfig['type'], $types)) {
                throw new \LogicException(
                    sprintf(
                        'Service must be one of the registered types (%s), "%s" given',
                        implode(', ', $types),
                        $serviceConfig['type']
                    )
                );
            }

            $grant = null;
            if (!empty($serviceConfig['role'])) {
                $grant = $serviceConfig['role'];
            }

            if (!empty($serviceConfig['expression'])) {
                if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
                    throw new \LogicException(
                        'Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'
                    );
                }

                if (null !== $grant) {
                    throw new \LogicException(<<<EOT
You cannot set both a role and expression for a service.
If you want to know how you can use the expression language
to check for roles, consult the documentation:

http://symfony.com/doc/current/book/security.html#complex-access-controls-with-expressions

EOT
                    );
                }

                $grant = new Definition('Symfony\Component\ExpressionLanguage\Expression');
                $grant->setPublic(false);
                $grant->addArgument($serviceConfig['expression']);
            }

            $id = sprintf('tree_house.keystone.service.%s', $name);
            $service = $container->setDefinition($id, new DefinitionDecorator('tree_house.keystone.service'));
            $service->replaceArgument(0, $name);
            $service->replaceArgument(1, $serviceConfig['type']);
            $service->replaceArgument(2, $grant ?: 'ROLE_USER');

            foreach ($serviceConfig['endpoint'] as $endpointConfig) {
                $service->addMethodCall('addEndpoint', [$endpointConfig['public_url'], $endpointConfig['admin_url']]);
            }

            $manager->addMethodCall('addService', [new Reference($id)]);
        }
    }
1033866
public function setService($name, $service, $parameters = null)
    {
        $name = strtolower($name);
        if ($service instanceof \Closure) {

            /**
             * Save directly the service in the
             * container.
             */
            $this->registerService($name, $service);

        } elseif (class_exists($service, true)) {

            /**
             * instantiation and initialization of
             * each service, return true on success
             * and false on error
             */
            $this->registerService($name, new $service($parameters));
        }
        return $this;
    }
556474
private function initializeMethodNamesMap($class)
    {
        $this->serviceIdToMethodNameMap = array();
        $this->usedMethodNames = array();

        if ($reflectionClass = $this->container->getReflectionClass($class)) {
            foreach ($reflectionClass->getMethods() as $method) {
                $this->usedMethodNames[strtolower($method->getName())] = true;
            }
        }
    }
389906
private function findUsedTypes($service, Type $type)
    {
        if ($type instanceof Enum) {
            return array($type);
        }
        if (!$type instanceof ComplexType) {
            return array();
        }

        $foundTypes = array($type);

        // Process Base type
        $baseType = $type->getBaseType();
        if ($baseType) {
            $foundTypes = array_merge($foundTypes, $this->findUsedTypes($service, $baseType));
        }

        $members = $type->getMembers();
        foreach ($members as $member) {
            /** @var Variable $member */
            // Remove array mark from type name
            $memberTypeName = str_replace('[]', '', $member->getType());
            $memberType = $service->getType($memberTypeName);
            if (!$memberType) {
                continue;
            }

            $foundTypes = array_merge($foundTypes, $this->findUsedTypes($service, $memberType));
        }

        return $foundTypes;
    }
160494
public function setClassTypes($classTypes)
    {
        if ($classTypes) {
            if (\is_string($classTypes)) {
                if (!\in_array($classTypes, $this->classTypes)) {
                    $this->classTypes[] = $classTypes;
                }
            } else {
                foreach ($classTypes as $classType) {
                    if (!\in_array($classType, $this->classTypes)) {
                        $this->classTypes[] = $classType;
                    }
                }
            }
        }
    }