diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php
index 6c5aaa3..b73aa07 100644
--- a/core/lib/Drupal/Core/Template/TwigEnvironment.php
+++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php
@@ -66,6 +66,9 @@ class TwigEnvironment extends \Twig_Environment {
    *   The options for the Twig environment.
    */
   public function __construct($root, CacheBackendInterface $cache, $twig_extension_hash, \Twig_LoaderInterface $loader = NULL, $options = array()) {
+    assert('file_exists($root)', 'Argument #1 must be a legal file path.');
+    assert('is_string($twig_extension_hash)', 'Argument #3 must be a string');
+
     $this->cache_object = $cache;
     $this->templateCacheFilenamePrefix = $twig_extension_hash;
 
@@ -100,8 +103,16 @@ protected function isFresh($cache_filename, $name) {
 
   /**
    * Compile the source and write the compiled template to disk.
+   *
+   * @param string $cache_filename
+   *   The cache filename.
+   * @param string $name
+   *   The template name.
    */
   public function updateCompiledTemplate($cache_filename, $name) {
+    assert('is_string($cache_filename) && !empty($cache_filename)', 'Argument #1 must be a string');
+    assert('is_string($name) && !empty($name)', 'Argument #2 must be a string');
+
     $source = $this->loader->getSource($name);
     $compiled_source = $this->compileSource($source, $name);
     $this->storage()->save($cache_filename, $compiled_source);
@@ -114,6 +125,8 @@ public function updateCompiledTemplate($cache_filename, $name) {
    * {@inheritdoc}
    */
   public function getCacheFilename($name) {
+    assert('is_string($name)', 'Argument must be a string');
+
     // We override the cache filename in order to avoid issues with not using
     // shared filesystems. The Twig templates for example rely on available Twig
     // extensions, so we use the twig extension hash which varies by extensions
@@ -152,6 +165,9 @@ public function getCacheFilename($name) {
    *   When an error occurred during compilation.
    */
   public function loadTemplate($name, $index = NULL) {
+    assert('is_string($name)', 'Argument #1 must be a string');
+    assert('is_null($index) || is_int($index)', 'Argument #2, if set, must be an integer');
+
     $cls = $this->getTemplateClass($name, $index);
 
     if (isset($this->loadedTemplates[$cls])) {
@@ -183,7 +199,9 @@ public function loadTemplate($name, $index = NULL) {
         $this->initRuntime();
     }
 
-    return $this->loadedTemplates[$cls] = new $cls($this);
+    $this->loadedTemplates[$cls] = new $cls($this);
+    assert('$this->loadedTemplates[$cls] instanceof \\Twig_TemplateInterface', 'Invalid Return');
+    return $this->loadedTemplates[$cls];
   }
 
   /**
@@ -210,6 +228,9 @@ protected function storage() {
    *   The template class name.
    */
   public function getTemplateClass($name, $index = NULL) {
+    assert('is_string($name)', 'Argument #1 must be a string');
+    assert('is_null($index) || is_int($index)', 'Argument #2, if set, must be an integer');
+
     // We override this method to add caching because it gets called multiple
     // times when the same template is used more than once. For example, a page
     // rendering 50 nodes without any node template overrides will use the same
@@ -218,6 +239,8 @@ public function getTemplateClass($name, $index = NULL) {
     if (!isset($this->templateClasses[$cache_index])) {
       $this->templateClasses[$cache_index] = $this->templateClassPrefix . hash('sha256', $this->loader->getCacheKey($name)) . (NULL === $index ? '' : '_' . $index);
     }
+
+    assert('is_string($this->templateClasses[$cache_index])', 'Invalid Return');
     return $this->templateClasses[$cache_index];
   }
 
@@ -244,9 +267,13 @@ public function getTemplateClass($name, $index = NULL) {
    * @see \Drupal\Core\Template\Loader\StringLoader::exists()
    */
   public function renderInline($template_string, array $context = array()) {
+    assert('is_string($template_string)', 'Argument #1 must be a string');
+
     // Prefix all inline templates with a special comment.
     $template_string = '{# inline_template_start #}' . $template_string;
-    return SafeString::create($this->loadTemplate($template_string, NULL)->render($context));
+    $return = SafeString::create($this->loadTemplate($template_string, NULL)->render($context));
+    assert('$return instanceof \\Drupal\\Component\\Utility\\SafeStringInterface || is_string($return)');
+    return $return;
   }
 
 }
